• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript data.Schema类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@orbit/data.Schema的典型用法代码示例。如果您正苦于以下问题:TypeScript Schema类的具体用法?TypeScript Schema怎么用?TypeScript Schema使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Schema类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: recordRemoved

export function recordRemoved(
  schema: Schema,
  record: Record
): RecordOperation[] {
  const ops: RecordOperation[] = [];
  const relationships = record && record.relationships;

  if (relationships) {
    const modelDef = schema.getModel(record.type);
    const recordIdentity = cloneRecordIdentity(record);

    Object.keys(relationships).forEach(relationship => {
      const relationshipDef = modelDef.relationships[relationship];
      const relationshipData =
        relationships[relationship] && relationships[relationship].data;
      const relatedRecords = recordArrayFromData(relationshipData);

      Array.prototype.push.apply(
        ops,
        removeRelatedRecordsOps(
          schema,
          recordIdentity,
          relationshipDef,
          relatedRecords
        )
      );
    });
  }

  return ops;
}
开发者ID:orbitjs,项目名称:orbit.js,代码行数:31,代码来源:schema-consistency-utils.ts


示例2: normalizeRecordProperties

export default function normalizeRecordProperties(
  schema: Schema,
  properties: Record<string, unknown>
) {
  const { id, type } = properties;
  const modelDefinition = schema.getModel(type as string);
  const record = { id, type } as OrbitRecord;

  assignKeys(modelDefinition, record, properties);
  assignAttributes(modelDefinition, record, properties);
  assignRelationships(modelDefinition, record, properties);

  return record;
}
开发者ID:orbitjs,项目名称:ember-orbit,代码行数:14,代码来源:normalize-record-properties.ts


示例3: recordReplaced

export function recordReplaced(
  schema: Schema,
  currentRecord: Record,
  record: Record
): RecordOperation[] {
  const ops: RecordOperation[] = [];

  if (record.relationships) {
    const modelDef = schema.getModel(record.type);
    const recordIdentity = cloneRecordIdentity(record);

    for (let relationship in record.relationships) {
      const relationshipDef = modelDef.relationships[relationship];
      const relationshipData =
        record && deepGet(record, ['relationships', relationship, 'data']);
      const currentRelationshipData =
        currentRecord &&
        deepGet(currentRecord, ['relationships', relationship, 'data']);

      if (relationshipDef.type === 'hasMany') {
        Array.prototype.push.apply(
          ops,
          relatedRecordsReplaced(
            schema,
            recordIdentity,
            relationship,
            currentRelationshipData,
            relationshipData
          )
        );
      } else {
        Array.prototype.push.apply(
          ops,
          relatedRecordReplaced(
            schema,
            recordIdentity,
            relationship,
            currentRelationshipData,
            relationshipData
          )
        );
      }
    }
  }

  return ops;
}
开发者ID:orbitjs,项目名称:orbit.js,代码行数:47,代码来源:schema-consistency-utils.ts


示例4: removeRelationshipOp

export function removeRelationshipOp(
  schema: Schema,
  record: RecordIdentity,
  relationship: string,
  relatedRecord: RecordIdentity
): RecordOperation {
  const relationshipDef = schema.getModel(record.type).relationships[
    relationship
  ];
  const isHasMany = relationshipDef.type === 'hasMany';

  return {
    op: isHasMany ? 'removeFromRelatedRecords' : 'replaceRelatedRecord',
    record,
    relationship,
    relatedRecord: isHasMany ? relatedRecord : null
  } as RecordOperation;
}
开发者ID:orbitjs,项目名称:orbit.js,代码行数:18,代码来源:schema-consistency-utils.ts


示例5: getInverseRelationship

export function getInverseRelationship(
  schema: Schema,
  record: RecordIdentity,
  relationship: string,
  relatedRecord: RecordIdentity
): RecordRelationshipIdentity {
  if (relatedRecord) {
    const relationshipDef = schema.getModel(record.type).relationships[
      relationship
    ];
    if (relationshipDef.inverse) {
      return {
        record,
        relationship,
        relatedRecord
      };
    }
  }
}
开发者ID:orbitjs,项目名称:orbit.js,代码行数:19,代码来源:cache-integrity-utils.ts


示例6: test

  test('#upgrade upgrades the cache to include new models introduced in a schema', async function(assert) {
    let person = {
      type: 'person',
      id: '1',
      relationships: { planet: { data: { type: 'planet', id: 'earth' } } }
    };

    let models = clone(schema.models);
    models.planet.relationships.inhabitants = {
      type: 'hasMany',
      model: 'person',
      inverse: 'planet'
    };
    models.person = {
      relationships: {
        planet: { type: 'hasOne', model: 'planet', inverse: 'inhabitants' }
      }
    };

    schema.upgrade({ models });

    await source.update(t => t.addRecord(person));

    assert.deepEqual(
      source.cache.getRecordSync({ type: 'person', id: '1' }),
      person,
      'records match'
    );
  });
开发者ID:orbitjs,项目名称:orbit.js,代码行数:29,代码来源:memory-source-test.ts


示例7: test

    test('Adding a record to the memory source immediately pushes the update to the remote', async function(assert) {
      assert.expect(1);

      await coordinator.activate();

      let planet: Record = {
        type: 'planet',
        id: schema.generateId(),
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      };

      fetchStub.withArgs('/planets').returns(
        jsonapiResponse(201, {
          data: {
            id: planet.id,
            type: 'planets',
            attributes: { name: 'Jupiter', classification: 'gas giant' }
          }
        })
      );

      await memory.update(t => t.addRecord(planet));

      let result = memory.cache.query(q => q.findRecord(planet));

      assert.deepEqual(result, {
        type: 'planet',
        id: planet.id,
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      });
    });
开发者ID:orbitjs,项目名称:orbit.js,代码行数:31,代码来源:store-jsonapi-clientid-pessimistic-test.ts


示例8: skip

  skip('will reopen the database when the schema is upgraded', async function(assert) {
    const done = assert.async();

    assert.expect(5);

    assert.equal(source.cache.dbVersion, 1, 'db starts with version == 1');

    source.cache.migrateDB = function(db, event) {
      assert.equal(
        event.oldVersion,
        1,
        'migrateDB called with oldVersion == 1'
      );
      assert.equal(
        event.newVersion,
        2,
        'migrateDB called with newVersion == 2'
      );
      done();
    };

    schema.on('upgrade', version => {
      assert.equal(version, 2, 'schema has upgraded to v2');
      assert.equal(source.cache.dbVersion, 2, 'db has the correct version');
    });

    await source.cache.openDB();

    await schema.upgrade({
      models: {
        planet: {
          attributes: {
            name: { type: 'string' }
          }
        },
        moon: {
          attributes: {
            name: { type: 'string' }
          }
        }
      }
    });
  });
开发者ID:orbitjs,项目名称:orbit.js,代码行数:43,代码来源:source-test.ts


示例9:

 .then(() => {
   schema.upgrade({
     models: {
       planet: {
         attributes: {
           name: { type: 'string' }
         }
       },
       moon: {
         attributes: {
           name: { type: 'string' }
         }
       }
     }
   });
 });
开发者ID:SmuliS,项目名称:orbit.js,代码行数:16,代码来源:source-test.ts


示例10: test

  test('Adding a record to the memory source queues an update request which will be pushed to the remote', async function(assert) {
    assert.expect(2);

    await coordinator.activate();

    fetchStub.withArgs('/planets').returns(
      jsonapiResponse(201, {
        data: {
          id: '12345',
          type: 'planets',
          attributes: { name: 'Jupiter', classification: 'gas giant' }
        }
      })
    );

    let planet: Record = {
      type: 'planet',
      id: schema.generateId(),
      attributes: { name: 'Jupiter', classification: 'gas giant' }
    };
    await memory.update(t => t.addRecord(planet));

    assert.deepEqual(
      memory.cache.query(q => q.findRecord(planet)),
      {
        type: 'planet',
        id: planet.id,
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      },
      'keys have not been syncd up yet - remote source still needs to process request'
    );

    await remote.requestQueue.process();

    assert.deepEqual(
      memory.cache.query(q => q.findRecord(planet)),
      {
        type: 'planet',
        id: planet.id,
        keys: { remoteId: '12345' },
        attributes: { name: 'Jupiter', classification: 'gas giant' }
      },
      'keys are syncd up after remote source finishes processing requests'
    );
  });
开发者ID:orbitjs,项目名称:orbit.js,代码行数:45,代码来源:store-jsonapi-remoteid-optimistic-test.ts



注:本文中的@orbit/data.Schema类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript data.Source类代码示例发布时间:2022-05-28
下一篇:
TypeScript data.Promise类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap