it('properly normalizes a nested object with arguments but without an ID', () => { const fragment = gql` fragment Item on ItemType { id, stringField, numberField, nullField, nestedObj(arg: "val") { stringField, numberField, nullField } } `; const result = { id: 'abcd', stringField: 'This is a string!', numberField: 5, nullField: null, nestedObj: { stringField: 'This is a string too!', numberField: 6, nullField: null, }, }; assert.deepEqual(writeFragmentToStore({ fragment, result: _.cloneDeep(result), }), { [result.id]: _.assign({}, _.assign({}, _.omit(result, 'nestedObj')), { 'nestedObj({"arg":"val"})': `${result.id}.nestedObj({"arg":"val"})`, }), [`${result.id}.nestedObj({"arg":"val"})`]: result.nestedObj, }); });
it('properly normalizes an array of non-objects with null', () => { const query = gql` { id, stringField, numberField, nullField, simpleArray } `; const result: any = { id: 'abcd', stringField: 'This is a string!', numberField: 5, nullField: null, simpleArray: [null, 'two', 'three'], }; const normalized = writeQueryToStore({ query, result: _.cloneDeep(result), }); assert.deepEqual(normalized, { 'ROOT_QUERY': _.assign({}, _.assign({}, _.omit(result, 'simpleArray')), { simpleArray: { type: 'json', json: [ result.simpleArray[0], result.simpleArray[1], result.simpleArray[2], ], }, }), }); });
it('properly normalizes an array of non-objects with null', () => { const query = gql` { id stringField numberField nullField simpleArray } `; const result: any = { id: 'abcd', stringField: 'This is a string!', numberField: 5, nullField: null, simpleArray: [null, 'two', 'three'], }; const normalized = writeQueryToStore({ query, result: cloneDeep(result), }); expect(normalized.toObject()).toEqual({ ROOT_QUERY: assign<{}>({}, assign({}, omit(result, 'simpleArray')), { simpleArray: { type: 'json', json: [ result.simpleArray[0], result.simpleArray[1], result.simpleArray[2], ], }, }), }); });
it('properly normalizes a nested object without an ID', () => { const fragment = ` fragment Item on ItemType { id, stringField, numberField, nullField, nestedObj { stringField, numberField, nullField } } `; const result = { id: 'abcd', stringField: 'This is a string!', numberField: 5, nullField: null, nestedObj: { stringField: 'This is a string too!', numberField: 6, nullField: null, }, }; assertEqualSansDataId(writeFragmentToStore({ fragment, result: _.cloneDeep(result), }), { [result.id]: _.assign({}, _.assign({}, _.omit(result, 'nestedObj')), { nestedObj: `${result.id}.nestedObj`, }), [`${result.id}.nestedObj`]: result.nestedObj, }); });
public async create(space: Space) { if (this.useRbac()) { this.debugLogger(`SpacesClient.create(), using RBAC. Checking if authorized globally`); await this.ensureAuthorizedGlobally( this.authorization.actions.space.manage, 'create', 'Unauthorized to create spaces' ); this.debugLogger(`SpacesClient.create(), using RBAC. Global authorization check succeeded`); } const repository = this.useRbac() ? this.internalSavedObjectRepository : this.callWithRequestSavedObjectRepository; const { total } = await repository.find({ type: 'space', page: 1, perPage: 0, }); if (total >= this.config.get('xpack.spaces.maxSpaces')) { throw Boom.badRequest( 'Unable to create Space, this exceeds the maximum number of spaces set by the xpack.spaces.maxSpaces setting' ); } this.debugLogger(`SpacesClient.create(), using RBAC. Attempting to create space`); const attributes = omit(space, ['id', '_reserved']); const id = space.id; const createdSavedObject = await repository.create('space', attributes, { id }); this.debugLogger(`SpacesClient.create(), created space object`); return this.transformSavedObjectToSpace(createdSavedObject); }
it('properly normalizes an array of non-objects with null', () => { const fragment = gql` fragment Item on ItemType { id, stringField, numberField, nullField, simpleArray } `; const result = { id: 'abcd', stringField: 'This is a string!', numberField: 5, nullField: null, simpleArray: [null, 'two', 'three'], }; const normalized = writeFragmentToStore({ fragment, result: _.cloneDeep(result), }); assert.deepEqual(normalized, { [result.id]: _.assign({}, _.assign({}, _.omit(result, 'simpleArray')), { simpleArray: { type: 'json', json: [ result.simpleArray[0], result.simpleArray[1], result.simpleArray[2], ], }, }), }); });
function createSettingsTransactionWithoutMemos( account: string, settings: Settings ): any { if (settings.regularKey !== undefined) { const removeRegularKey = { TransactionType: 'SetRegularKey', Account: account } if (settings.regularKey === null) { return removeRegularKey } return _.assign({}, removeRegularKey, {RegularKey: settings.regularKey}) } if (settings.signers !== undefined) { return { TransactionType: 'SignerListSet', Account: account, SignerQuorum: settings.signers.threshold, SignerEntries: _.map(settings.signers.weights, formatSignerEntry) } } const txJSON: any = { TransactionType: 'AccountSet', Account: account } setTransactionFlags(txJSON, _.omit(settings, 'memos')) setTransactionFields(txJSON, settings) if (txJSON.TransferRate !== undefined) { txJSON.TransferRate = convertTransferRate(txJSON.TransferRate) } return txJSON }
it('properly normalizes a nested object that returns null', () => { const query = gql` { id stringField numberField nullField nestedObj { id stringField numberField nullField } } `; const result: any = { id: 'abcd', stringField: 'This is a string!', numberField: 5, nullField: null, nestedObj: null, }; assert.deepEqual<NormalizedCache>( writeQueryToStore({ query, result: cloneDeep(result), }), { ROOT_QUERY: assign({}, assign({}, omit(result, 'nestedObj')), { nestedObj: null, }), }, ); });
public async getBeatWithToken( user: FrameworkUser, enrollmentToken: string ): Promise<CMBeat | null> { const params = { ignore: [404], index: INDEX_NAMES.BEATS, type: '_doc', body: { query: { match: { 'beat.enrollment_token': enrollmentToken }, }, }, }; const response = await this.database.search(user, params); const beats = _get<CMBeat[]>(response, 'hits.hits', []); if (beats.length === 0) { return null; } return omit<CMBeat, {}>(_get<CMBeat>(beats[0], '_source.beat'), ['access_token']); }
function semColors(state: ColorMapping = defaultSemColorMap, action: FSA): ColorMapping { const moduleCode = get(action, 'payload.moduleCode'); if (!moduleCode) return state; switch (action.type) { case ADD_MODULE: return { ...state, [moduleCode]: getNewColor(values(state)), }; case REMOVE_MODULE: return omit(state, moduleCode); case SELECT_MODULE_COLOR: return { ...state, [moduleCode]: action.payload.colorIndex, }; default: return state; } }