@instantdb/core 0.22.97 → 0.22.98-experimental.drewh-ts-target.20762041587.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/commonjs/Connection.js +50 -51
  2. package/dist/commonjs/Connection.js.map +1 -1
  3. package/dist/commonjs/InMemoryStorage.js +13 -32
  4. package/dist/commonjs/InMemoryStorage.js.map +1 -1
  5. package/dist/commonjs/IndexedDBStorage.js +193 -217
  6. package/dist/commonjs/IndexedDBStorage.js.map +1 -1
  7. package/dist/commonjs/InstantError.js +1 -0
  8. package/dist/commonjs/InstantError.js.map +1 -1
  9. package/dist/commonjs/Reactor.js +566 -610
  10. package/dist/commonjs/Reactor.js.map +1 -1
  11. package/dist/commonjs/StorageAPI.js +51 -70
  12. package/dist/commonjs/StorageAPI.js.map +1 -1
  13. package/dist/commonjs/SyncTable.js +68 -81
  14. package/dist/commonjs/SyncTable.js.map +1 -1
  15. package/dist/commonjs/WindowNetworkListener.js +2 -13
  16. package/dist/commonjs/WindowNetworkListener.js.map +1 -1
  17. package/dist/commonjs/__types__/fieldsTypeTest.js +8 -16
  18. package/dist/commonjs/__types__/fieldsTypeTest.js.map +1 -1
  19. package/dist/commonjs/__types__/useDatesTypeTest.js +3 -6
  20. package/dist/commonjs/__types__/useDatesTypeTest.js.map +1 -1
  21. package/dist/commonjs/authAPI.js +62 -79
  22. package/dist/commonjs/authAPI.js.map +1 -1
  23. package/dist/commonjs/createRouteHandler.js +5 -15
  24. package/dist/commonjs/createRouteHandler.js.map +1 -1
  25. package/dist/commonjs/datalog.js +1 -1
  26. package/dist/commonjs/datalog.js.map +1 -1
  27. package/dist/commonjs/devtool.js +26 -8
  28. package/dist/commonjs/devtool.js.map +1 -1
  29. package/dist/commonjs/framework.d.ts.map +1 -1
  30. package/dist/commonjs/framework.js +142 -152
  31. package/dist/commonjs/framework.js.map +1 -1
  32. package/dist/commonjs/index.js +204 -190
  33. package/dist/commonjs/index.js.map +1 -1
  34. package/dist/commonjs/instaml.js +44 -30
  35. package/dist/commonjs/instaml.js.map +1 -1
  36. package/dist/commonjs/instaql.js +25 -33
  37. package/dist/commonjs/instaql.js.map +1 -1
  38. package/dist/commonjs/parseSchemaFromJSON.js +6 -7
  39. package/dist/commonjs/parseSchemaFromJSON.js.map +1 -1
  40. package/dist/commonjs/presence.js +7 -8
  41. package/dist/commonjs/presence.js.map +1 -1
  42. package/dist/commonjs/queryValidation.js +1 -2
  43. package/dist/commonjs/queryValidation.js.map +1 -1
  44. package/dist/commonjs/schema.js +8 -6
  45. package/dist/commonjs/schema.js.map +1 -1
  46. package/dist/commonjs/schemaTypes.js +22 -3
  47. package/dist/commonjs/schemaTypes.js.map +1 -1
  48. package/dist/commonjs/store.js +29 -38
  49. package/dist/commonjs/store.js.map +1 -1
  50. package/dist/commonjs/transactionValidation.js +1 -2
  51. package/dist/commonjs/transactionValidation.js.map +1 -1
  52. package/dist/commonjs/utils/Deferred.js +3 -0
  53. package/dist/commonjs/utils/Deferred.js.map +1 -1
  54. package/dist/commonjs/utils/PersistedObject.js +216 -233
  55. package/dist/commonjs/utils/PersistedObject.js.map +1 -1
  56. package/dist/commonjs/utils/fetch.js +9 -19
  57. package/dist/commonjs/utils/fetch.js.map +1 -1
  58. package/dist/commonjs/utils/linkIndex.js +2 -4
  59. package/dist/commonjs/utils/linkIndex.js.map +1 -1
  60. package/dist/commonjs/utils/object.js +1 -1
  61. package/dist/commonjs/utils/object.js.map +1 -1
  62. package/dist/esm/Connection.js +50 -51
  63. package/dist/esm/Connection.js.map +1 -1
  64. package/dist/esm/InMemoryStorage.js +13 -32
  65. package/dist/esm/InMemoryStorage.js.map +1 -1
  66. package/dist/esm/IndexedDBStorage.js +193 -217
  67. package/dist/esm/IndexedDBStorage.js.map +1 -1
  68. package/dist/esm/InstantError.js +1 -0
  69. package/dist/esm/InstantError.js.map +1 -1
  70. package/dist/esm/Reactor.js +566 -610
  71. package/dist/esm/Reactor.js.map +1 -1
  72. package/dist/esm/StorageAPI.js +51 -70
  73. package/dist/esm/StorageAPI.js.map +1 -1
  74. package/dist/esm/SyncTable.js +68 -81
  75. package/dist/esm/SyncTable.js.map +1 -1
  76. package/dist/esm/WindowNetworkListener.js +2 -13
  77. package/dist/esm/WindowNetworkListener.js.map +1 -1
  78. package/dist/esm/__types__/fieldsTypeTest.js +8 -16
  79. package/dist/esm/__types__/fieldsTypeTest.js.map +1 -1
  80. package/dist/esm/__types__/useDatesTypeTest.js +3 -6
  81. package/dist/esm/__types__/useDatesTypeTest.js.map +1 -1
  82. package/dist/esm/authAPI.js +62 -79
  83. package/dist/esm/authAPI.js.map +1 -1
  84. package/dist/esm/createRouteHandler.js +5 -15
  85. package/dist/esm/createRouteHandler.js.map +1 -1
  86. package/dist/esm/datalog.js +1 -1
  87. package/dist/esm/datalog.js.map +1 -1
  88. package/dist/esm/devtool.js +26 -8
  89. package/dist/esm/devtool.js.map +1 -1
  90. package/dist/esm/framework.d.ts.map +1 -1
  91. package/dist/esm/framework.js +142 -152
  92. package/dist/esm/framework.js.map +1 -1
  93. package/dist/esm/index.js +204 -190
  94. package/dist/esm/index.js.map +1 -1
  95. package/dist/esm/instaml.js +44 -30
  96. package/dist/esm/instaml.js.map +1 -1
  97. package/dist/esm/instaql.js +25 -33
  98. package/dist/esm/instaql.js.map +1 -1
  99. package/dist/esm/parseSchemaFromJSON.js +6 -7
  100. package/dist/esm/parseSchemaFromJSON.js.map +1 -1
  101. package/dist/esm/presence.js +7 -8
  102. package/dist/esm/presence.js.map +1 -1
  103. package/dist/esm/queryValidation.js +1 -2
  104. package/dist/esm/queryValidation.js.map +1 -1
  105. package/dist/esm/schema.js +8 -6
  106. package/dist/esm/schema.js.map +1 -1
  107. package/dist/esm/schemaTypes.js +22 -3
  108. package/dist/esm/schemaTypes.js.map +1 -1
  109. package/dist/esm/store.js +29 -38
  110. package/dist/esm/store.js.map +1 -1
  111. package/dist/esm/transactionValidation.js +1 -2
  112. package/dist/esm/transactionValidation.js.map +1 -1
  113. package/dist/esm/utils/Deferred.js +3 -0
  114. package/dist/esm/utils/Deferred.js.map +1 -1
  115. package/dist/esm/utils/PersistedObject.js +216 -233
  116. package/dist/esm/utils/PersistedObject.js.map +1 -1
  117. package/dist/esm/utils/fetch.js +9 -19
  118. package/dist/esm/utils/fetch.js.map +1 -1
  119. package/dist/esm/utils/linkIndex.js +2 -4
  120. package/dist/esm/utils/linkIndex.js.map +1 -1
  121. package/dist/esm/utils/object.js +1 -1
  122. package/dist/esm/utils/object.js.map +1 -1
  123. package/dist/standalone/index.js +2610 -2367
  124. package/dist/standalone/index.umd.cjs +3 -3
  125. package/package.json +2 -2
  126. package/src/framework.ts +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"queryValidation.js","sourceRoot":"","sources":["../../src/queryValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,GAEZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,MAAM,CAAC;AAEhD,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe,EAAE,IAAa;QACxC,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,YAAY,IAAI,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACrE,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAED,MAAM,cAAc,GAAG;IACrB,OAAO;IACP,OAAO;IACP,OAAO;IACP,MAAM;IACN,OAAO;IACP,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,WAAW;CACZ,CAAC;AAIF,MAAM,WAAW,GAAG,CAClB,OAAmC,EAChB,EAAE;IACrB,OAAO,OAAO,CAAC,SAAS,IAAI,SAAS,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,mBAAmB,GAAG,CAC1B,KAAc,EAC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AAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChD,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,oBAAoB,CAC5B,sDAAsD,OAAO,WAAW,EAAE,EAC1E,WAAW,CACZ,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE,CAAC;YACpC,MAAM,IAAI,oBAAoB,CAC5B,sDAAsD,OAAO,WAAW,EAAE,EAC1E,WAAW,CACZ,CAAC;QACJ,CAAC;QAED,IAAI,WAAW,KAAK,cAAc,EAAE,CAAC;YACnC,SAAS;QACX,CAAC;QAED,uCAAuC;QACvC,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;gBAClC,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBACvD,MAAM,IAAI,oBAAoB,CAC5B,WAAW,WAAW,mDAAmD,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAC/I,WAAW,CACZ,CAAC;YACJ,CAAC;QACH,CAAC;QAED,qBAAqB,CACnB,QAAQ,CAAC,WAAW,CAA4B,EAChD,WAAW,EACX,MAAM,EACN,WAAW,EACX,CAAC,CACF,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n IContainEntitiesAndLinks,\n DataAttrDef,\n ValueTypes,\n} from './schemaTypes.ts';\nimport { validate as validateUUID } from 'uuid';\n\nexport class QueryValidationError extends Error {\n constructor(message: string, path?: string) {\n const fullMessage = path ? `At path '${path}': ${message}` : message;\n super(fullMessage);\n this.name = 'QueryValidationError';\n }\n}\n\nconst dollarSignKeys = [\n 'where',\n 'order',\n 'limit',\n 'last',\n 'first',\n 'offset',\n 'after',\n 'before',\n 'fields',\n 'aggregate',\n];\n\ntype PossibleAttrTypes = ValueTypes | 'unknown';\n\nconst getAttrType = (\n attrDef: DataAttrDef<any, any, any>,\n): PossibleAttrTypes => {\n return attrDef.valueType || 'unknown';\n};\n\nconst isValidValueForType = (\n value: unknown,\n expectedType: PossibleAttrTypes,\n isAnyType: boolean = false,\n): boolean => {\n if (isAnyType) return true;\n if (value === null || value === undefined) return true;\n\n switch (expectedType) {\n case 'string':\n return typeof value === 'string';\n case 'number':\n return typeof value === 'number' && !isNaN(value);\n case 'boolean':\n return typeof value === 'boolean';\n case 'date':\n return (\n value instanceof Date ||\n typeof value === 'string' ||\n typeof value === 'number'\n );\n default:\n return true;\n }\n};\n\nconst validateOperator = (\n op: string,\n opValue: unknown,\n expectedType: PossibleAttrTypes,\n attrName: string,\n entityName: string,\n attrDef: DataAttrDef<any, any, any>,\n path: string,\n) => {\n const isAnyType = attrDef.valueType === 'json';\n const assertValidValue = (\n op: string,\n expectedType: PossibleAttrTypes,\n opValue: unknown,\n ) => {\n if (!isValidValueForType(opValue, expectedType, isAnyType)) {\n throw new QueryValidationError(\n `Invalid value for operator '${op}' on attribute '${attrName}' in entity '${entityName}'. Expected ${expectedType}, but received: ${typeof opValue}`,\n path,\n );\n }\n };\n\n switch (op) {\n case 'in':\n case '$in':\n if (!Array.isArray(opValue)) {\n throw new QueryValidationError(\n `Operator '${op}' for attribute '${attrName}' in entity '${entityName}' must be an array, but received: ${typeof opValue}`,\n path,\n );\n }\n for (const item of opValue) {\n assertValidValue(op, expectedType, item);\n }\n break;\n case '$not':\n case '$ne':\n case '$gt':\n case '$lt':\n case '$gte':\n case '$lte':\n assertValidValue(op, expectedType, opValue);\n break;\n case '$like':\n case '$ilike':\n assertValidValue(op, 'string', opValue);\n\n if (op === '$ilike') {\n if (!attrDef.isIndexed) {\n throw new QueryValidationError(\n `Operator '${op}' can only be used with indexed attributes, but '${attrName}' in entity '${entityName}' is not indexed`,\n path,\n );\n }\n }\n\n break;\n case '$isNull':\n assertValidValue(op, 'boolean', opValue);\n break;\n default:\n throw new QueryValidationError(\n `Unknown operator '${op}' for attribute '${attrName}' in entity '${entityName}'`,\n path,\n );\n }\n};\n\nconst validateWhereClauseValue = (\n value: unknown,\n attrName: string,\n attrDef: DataAttrDef<any, any, any>,\n entityName: string,\n path: string,\n): void => {\n const expectedType = getAttrType(attrDef);\n const isAnyType = attrDef.valueType === 'json';\n\n const isComplexObject =\n typeof value === 'object' && value !== null && !Array.isArray(value);\n if (isComplexObject) {\n // For any type, allow complex objects without treating them as operators\n if (isAnyType) {\n return; // Any type accepts any value, including complex objects\n }\n\n const operators = value as Record<string, unknown>;\n\n for (const [op, opValue] of Object.entries(operators)) {\n validateOperator(\n op,\n opValue,\n expectedType,\n attrName,\n entityName,\n attrDef,\n `${path}.${op}`,\n );\n }\n } else {\n if (!isValidValueForType(value, expectedType, isAnyType)) {\n throw new QueryValidationError(\n `Invalid value for attribute '${attrName}' in entity '${entityName}'. Expected ${expectedType}, but received: ${typeof value}`,\n path,\n );\n }\n }\n};\n\nconst validateDotNotationAttribute = (\n dotPath: string,\n value: unknown,\n startEntityName: string,\n schema: IContainEntitiesAndLinks<any, any>,\n path: string,\n): void => {\n const pathParts = dotPath.split('.');\n if (pathParts.length < 2) {\n throw new QueryValidationError(\n `Invalid dot notation path '${dotPath}'. Must contain at least one dot.`,\n path,\n );\n }\n\n let currentEntityName = startEntityName;\n\n // Traverse all path parts except the last one (which should be an attribute)\n for (let i = 0; i < pathParts.length - 1; i++) {\n const linkName = pathParts[i];\n const currentEntity = schema.entities[currentEntityName];\n\n if (!currentEntity) {\n throw new QueryValidationError(\n `Entity '${currentEntityName}' does not exist in schema while traversing dot notation path '${dotPath}'.`,\n path,\n );\n }\n\n const link = currentEntity.links[linkName];\n if (!link) {\n const availableLinks = Object.keys(currentEntity.links);\n throw new QueryValidationError(\n `Link '${linkName}' does not exist on entity '${currentEntityName}' in dot notation path '${dotPath}'. Available links: ${availableLinks.length > 0 ? availableLinks.join(', ') : 'none'}`,\n path,\n );\n }\n\n currentEntityName = link.entityName;\n }\n\n // Validate the final attribute\n const finalAttrName = pathParts[pathParts.length - 1];\n const finalEntity = schema.entities[currentEntityName];\n\n if (!finalEntity) {\n throw new QueryValidationError(\n `Target entity '${currentEntityName}' does not exist in schema for dot notation path '${dotPath}'.`,\n path,\n );\n }\n\n // Handle 'id' field specially - every entity has an id field\n if (finalAttrName === 'id') {\n if (typeof value == 'string' && !validateUUID(value)) {\n throw new QueryValidationError(\n `Invalid value for id field in entity '${currentEntityName}'. Expected a UUID, but received: ${value}`,\n path,\n );\n }\n validateWhereClauseValue(\n value,\n dotPath,\n new DataAttrDef('string', false, true),\n startEntityName,\n path,\n );\n return;\n }\n\n const attrDef = finalEntity.attrs[finalAttrName];\n\n if (Object.keys(finalEntity.links).includes(finalAttrName)) {\n if (typeof value === 'string' && !validateUUID(value)) {\n throw new QueryValidationError(\n `Invalid value for link '${finalAttrName}' in entity '${currentEntityName}'. Expected a UUID, but received: ${value}`,\n path,\n );\n }\n\n validateWhereClauseValue(\n value,\n dotPath,\n new DataAttrDef('string', false, true),\n startEntityName,\n path,\n );\n return;\n }\n\n if (!attrDef) {\n const availableAttrs = Object.keys(finalEntity.attrs);\n throw new QueryValidationError(\n `Attribute '${finalAttrName}' does not exist on entity '${currentEntityName}' in dot notation path '${dotPath}'. Available attributes: ${availableAttrs.length > 0 ? availableAttrs.join(', ') + ', id' : 'id'}`,\n path,\n );\n }\n\n // Validate the value against the attribute type\n validateWhereClauseValue(value, dotPath, attrDef, startEntityName, path);\n};\n\nconst validateWhereClause = (\n whereClause: Record<string, unknown>,\n entityName: string,\n schema: IContainEntitiesAndLinks<any, any>,\n path: string,\n): void => {\n for (const [key, value] of Object.entries(whereClause)) {\n if (key === 'or' || key === 'and') {\n if (Array.isArray(value)) {\n for (const clause of value) {\n if (typeof clause === 'object' && clause !== null) {\n validateWhereClause(\n clause as Record<string, unknown>,\n entityName,\n schema,\n `${path}.${key}[${clause}]`,\n );\n }\n }\n }\n continue;\n }\n\n if (key === 'id') {\n validateWhereClauseValue(\n value,\n 'id',\n new DataAttrDef('string', false, true),\n entityName,\n `${path}.id`,\n );\n continue;\n }\n\n if (key.includes('.')) {\n validateDotNotationAttribute(\n key,\n value,\n entityName,\n schema,\n `${path}.${key}`,\n );\n continue;\n }\n\n const entityDef = schema.entities[entityName];\n if (!entityDef) continue;\n\n const attrDef = entityDef.attrs[key];\n const linkDef = entityDef.links[key];\n\n if (!attrDef && !linkDef) {\n const availableAttrs = Object.keys(entityDef.attrs);\n const availableLinks = Object.keys(entityDef.links);\n throw new QueryValidationError(\n `Attribute or link '${key}' does not exist on entity '${entityName}'. Available attributes: ${availableAttrs.length > 0 ? availableAttrs.join(', ') : 'none'}. Available links: ${availableLinks.length > 0 ? availableLinks.join(', ') : 'none'}`,\n `${path}.${key}`,\n );\n }\n\n if (attrDef) {\n validateWhereClauseValue(\n value,\n key,\n attrDef,\n entityName,\n `${path}.${key}`,\n );\n } else if (linkDef) {\n // For links, we expect the value to be a string (ID of the linked entity)\n // Create a synthetic string attribute definition for validation\n if (typeof value === 'string' && !validateUUID(value)) {\n throw new QueryValidationError(\n `Invalid value for link '${key}' in entity '${entityName}'. Expected a UUID, but received: ${value}`,\n `${path}.${key}`,\n );\n }\n const syntheticAttrDef = new DataAttrDef('string', false, true);\n validateWhereClauseValue(\n value,\n key,\n syntheticAttrDef,\n entityName,\n `${path}.${key}`,\n );\n }\n }\n};\n\nconst validateDollarObject = (\n dollarObj: Record<string, unknown>,\n entityName: string,\n schema?: IContainEntitiesAndLinks<any, any> | null | undefined,\n path?: string,\n depth: number = 0,\n): void => {\n for (const key of Object.keys(dollarObj)) {\n if (!dollarSignKeys.includes(key)) {\n throw new QueryValidationError(\n `Invalid query parameter '${key}' in $ object. Valid parameters are: ${dollarSignKeys.join(', ')}. Found: ${key}`,\n path,\n );\n }\n }\n\n // Validate that pagination parameters are only used at top-level\n const paginationParams = [\n // 'limit', // only supported client side\n 'offset',\n 'before',\n 'after',\n 'first',\n 'last',\n ];\n for (const param of paginationParams) {\n if (dollarObj[param] !== undefined && depth > 0) {\n throw new QueryValidationError(\n `'${param}' can only be used on top-level namespaces. It cannot be used in nested queries.`,\n path,\n );\n }\n }\n\n if (dollarObj.where && schema) {\n if (typeof dollarObj.where !== 'object' || dollarObj.where === null) {\n throw new QueryValidationError(\n `'where' clause must be an object in entity '${entityName}', but received: ${typeof dollarObj.where}`,\n path ? `${path}.where` : undefined,\n );\n }\n validateWhereClause(\n dollarObj.where as Record<string, unknown>,\n entityName,\n schema,\n path ? `${path}.where` : 'where',\n );\n }\n};\n\nconst validateEntityInQuery = (\n queryPart: Record<string, unknown>,\n entityName: string,\n schema: IContainEntitiesAndLinks<any, any> | null | undefined,\n path: string,\n depth: number = 0,\n): void => {\n if (!queryPart || typeof queryPart !== 'object') {\n throw new QueryValidationError(\n `Query part for entity '${entityName}' must be an object, but received: ${typeof queryPart}`,\n path,\n );\n }\n\n for (const key of Object.keys(queryPart)) {\n if (key !== '$') {\n // Validate link exists\n if (schema && !(key in schema.entities[entityName].links)) {\n const availableLinks = Object.keys(schema.entities[entityName].links);\n throw new QueryValidationError(\n `Link '${key}' does not exist on entity '${entityName}'. Available links: ${availableLinks.length > 0 ? availableLinks.join(', ') : 'none'}`,\n `${path}.${key}`,\n );\n }\n\n // Recursively validate nested query\n const nestedQuery = queryPart[key];\n if (typeof nestedQuery === 'object' && nestedQuery !== null) {\n const linkedEntityName =\n schema?.entities[entityName].links[key]?.entityName;\n if (linkedEntityName) {\n validateEntityInQuery(\n nestedQuery as Record<string, unknown>,\n linkedEntityName,\n schema,\n `${path}.${key}`,\n depth + 1,\n );\n }\n }\n } else {\n // Validate $ object\n const dollarObj = queryPart[key];\n if (typeof dollarObj !== 'object' || dollarObj === null) {\n throw new QueryValidationError(\n `Query parameter '$' must be an object in entity '${entityName}', but received: ${typeof dollarObj}`,\n `${path}.$`,\n );\n }\n\n validateDollarObject(\n dollarObj as Record<string, unknown>,\n entityName,\n schema,\n `${path}.$`,\n depth,\n );\n }\n }\n};\n\nexport const validateQuery = (\n q: unknown,\n schema?: IContainEntitiesAndLinks<any, any>,\n): void => {\n if (typeof q !== 'object' || q === null) {\n throw new QueryValidationError(\n `Query must be an object, but received: ${typeof q}${q === null ? ' (null)' : ''}`,\n );\n }\n\n if (Array.isArray(q)) {\n throw new QueryValidationError(\n `Query must be an object, but received: ${typeof q}`,\n );\n }\n\n const queryObj = q as Record<string, unknown>;\n\n for (const topLevelKey of Object.keys(queryObj)) {\n if (Array.isArray(q[topLevelKey])) {\n throw new QueryValidationError(\n `Query keys must be strings, but found key of type: ${typeof topLevelKey}`,\n topLevelKey,\n );\n }\n\n if (typeof topLevelKey !== 'string') {\n throw new QueryValidationError(\n `Query keys must be strings, but found key of type: ${typeof topLevelKey}`,\n topLevelKey,\n );\n }\n\n if (topLevelKey === '$$ruleParams') {\n continue;\n }\n\n // Check if the key is top level entity\n if (schema) {\n if (!schema.entities[topLevelKey]) {\n const availableEntities = Object.keys(schema.entities);\n throw new QueryValidationError(\n `Entity '${topLevelKey}' does not exist in schema. Available entities: ${availableEntities.length > 0 ? availableEntities.join(', ') : 'none'}`,\n topLevelKey,\n );\n }\n }\n\n validateEntityInQuery(\n queryObj[topLevelKey] as Record<string, unknown>,\n topLevelKey,\n schema,\n topLevelKey,\n 0, // Start at depth 0 for top-level entities\n );\n }\n};\n"]}
1
+ {"version":3,"file":"queryValidation.js","sourceRoot":"","sources":["../../src/queryValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,GAEZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,MAAM,CAAC;AAEhD,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAe,EAAE,IAAa;QACxC,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,YAAY,IAAI,MA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C;YACJ,CAAC;QACH,CAAC;QAED,qBAAqB,CACnB,QAAQ,CAAC,WAAW,CAA4B,EAChD,WAAW,EACX,MAAM,EACN,WAAW,EACX,CAAC,CACF,CAAC;IACJ,CAAC;AACH,CAAC,CAAC","sourcesContent":["import {\n IContainEntitiesAndLinks,\n DataAttrDef,\n ValueTypes,\n} from './schemaTypes.ts';\nimport { validate as validateUUID } from 'uuid';\n\nexport class QueryValidationError extends Error {\n constructor(message: string, path?: string) {\n const fullMessage = path ? `At path '${path}': ${message}` : message;\n super(fullMessage);\n this.name = 'QueryValidationError';\n }\n}\n\nconst dollarSignKeys = [\n 'where',\n 'order',\n 'limit',\n 'last',\n 'first',\n 'offset',\n 'after',\n 'before',\n 'fields',\n 'aggregate',\n];\n\ntype PossibleAttrTypes = ValueTypes | 'unknown';\n\nconst getAttrType = (\n attrDef: DataAttrDef<any, any, any>,\n): PossibleAttrTypes => {\n return attrDef.valueType || 'unknown';\n};\n\nconst isValidValueForType = (\n value: unknown,\n expectedType: PossibleAttrTypes,\n isAnyType: boolean = false,\n): boolean => {\n if (isAnyType) return true;\n if (value === null || value === undefined) return true;\n\n switch (expectedType) {\n case 'string':\n return typeof value === 'string';\n case 'number':\n return typeof value === 'number' && !isNaN(value);\n case 'boolean':\n return typeof value === 'boolean';\n case 'date':\n return (\n value instanceof Date ||\n typeof value === 'string' ||\n typeof value === 'number'\n );\n default:\n return true;\n }\n};\n\nconst validateOperator = (\n op: string,\n opValue: unknown,\n expectedType: PossibleAttrTypes,\n attrName: string,\n entityName: string,\n attrDef: DataAttrDef<any, any, any>,\n path: string,\n) => {\n const isAnyType = attrDef.valueType === 'json';\n const assertValidValue = (\n op: string,\n expectedType: PossibleAttrTypes,\n opValue: unknown,\n ) => {\n if (!isValidValueForType(opValue, expectedType, isAnyType)) {\n throw new QueryValidationError(\n `Invalid value for operator '${op}' on attribute '${attrName}' in entity '${entityName}'. Expected ${expectedType}, but received: ${typeof opValue}`,\n path,\n );\n }\n };\n\n switch (op) {\n case 'in':\n case '$in':\n if (!Array.isArray(opValue)) {\n throw new QueryValidationError(\n `Operator '${op}' for attribute '${attrName}' in entity '${entityName}' must be an array, but received: ${typeof opValue}`,\n path,\n );\n }\n for (const item of opValue) {\n assertValidValue(op, expectedType, item);\n }\n break;\n case '$not':\n case '$ne':\n case '$gt':\n case '$lt':\n case '$gte':\n case '$lte':\n assertValidValue(op, expectedType, opValue);\n break;\n case '$like':\n case '$ilike':\n assertValidValue(op, 'string', opValue);\n\n if (op === '$ilike') {\n if (!attrDef.isIndexed) {\n throw new QueryValidationError(\n `Operator '${op}' can only be used with indexed attributes, but '${attrName}' in entity '${entityName}' is not indexed`,\n path,\n );\n }\n }\n\n break;\n case '$isNull':\n assertValidValue(op, 'boolean', opValue);\n break;\n default:\n throw new QueryValidationError(\n `Unknown operator '${op}' for attribute '${attrName}' in entity '${entityName}'`,\n path,\n );\n }\n};\n\nconst validateWhereClauseValue = (\n value: unknown,\n attrName: string,\n attrDef: DataAttrDef<any, any, any>,\n entityName: string,\n path: string,\n): void => {\n const expectedType = getAttrType(attrDef);\n const isAnyType = attrDef.valueType === 'json';\n\n const isComplexObject =\n typeof value === 'object' && value !== null && !Array.isArray(value);\n if (isComplexObject) {\n // For any type, allow complex objects without treating them as operators\n if (isAnyType) {\n return; // Any type accepts any value, including complex objects\n }\n\n const operators = value as Record<string, unknown>;\n\n for (const [op, opValue] of Object.entries(operators)) {\n validateOperator(\n op,\n opValue,\n expectedType,\n attrName,\n entityName,\n attrDef,\n `${path}.${op}`,\n );\n }\n } else {\n if (!isValidValueForType(value, expectedType, isAnyType)) {\n throw new QueryValidationError(\n `Invalid value for attribute '${attrName}' in entity '${entityName}'. Expected ${expectedType}, but received: ${typeof value}`,\n path,\n );\n }\n }\n};\n\nconst validateDotNotationAttribute = (\n dotPath: string,\n value: unknown,\n startEntityName: string,\n schema: IContainEntitiesAndLinks<any, any>,\n path: string,\n): void => {\n const pathParts = dotPath.split('.');\n if (pathParts.length < 2) {\n throw new QueryValidationError(\n `Invalid dot notation path '${dotPath}'. Must contain at least one dot.`,\n path,\n );\n }\n\n let currentEntityName = startEntityName;\n\n // Traverse all path parts except the last one (which should be an attribute)\n for (let i = 0; i < pathParts.length - 1; i++) {\n const linkName = pathParts[i];\n const currentEntity = schema.entities[currentEntityName];\n\n if (!currentEntity) {\n throw new QueryValidationError(\n `Entity '${currentEntityName}' does not exist in schema while traversing dot notation path '${dotPath}'.`,\n path,\n );\n }\n\n const link = currentEntity.links[linkName];\n if (!link) {\n const availableLinks = Object.keys(currentEntity.links);\n throw new QueryValidationError(\n `Link '${linkName}' does not exist on entity '${currentEntityName}' in dot notation path '${dotPath}'. Available links: ${availableLinks.length > 0 ? availableLinks.join(', ') : 'none'}`,\n path,\n );\n }\n\n currentEntityName = link.entityName;\n }\n\n // Validate the final attribute\n const finalAttrName = pathParts[pathParts.length - 1];\n const finalEntity = schema.entities[currentEntityName];\n\n if (!finalEntity) {\n throw new QueryValidationError(\n `Target entity '${currentEntityName}' does not exist in schema for dot notation path '${dotPath}'.`,\n path,\n );\n }\n\n // Handle 'id' field specially - every entity has an id field\n if (finalAttrName === 'id') {\n if (typeof value == 'string' && !validateUUID(value)) {\n throw new QueryValidationError(\n `Invalid value for id field in entity '${currentEntityName}'. Expected a UUID, but received: ${value}`,\n path,\n );\n }\n validateWhereClauseValue(\n value,\n dotPath,\n new DataAttrDef('string', false, true),\n startEntityName,\n path,\n );\n return;\n }\n\n const attrDef = finalEntity.attrs[finalAttrName];\n\n if (Object.keys(finalEntity.links).includes(finalAttrName)) {\n if (typeof value === 'string' && !validateUUID(value)) {\n throw new QueryValidationError(\n `Invalid value for link '${finalAttrName}' in entity '${currentEntityName}'. Expected a UUID, but received: ${value}`,\n path,\n );\n }\n\n validateWhereClauseValue(\n value,\n dotPath,\n new DataAttrDef('string', false, true),\n startEntityName,\n path,\n );\n return;\n }\n\n if (!attrDef) {\n const availableAttrs = Object.keys(finalEntity.attrs);\n throw new QueryValidationError(\n `Attribute '${finalAttrName}' does not exist on entity '${currentEntityName}' in dot notation path '${dotPath}'. Available attributes: ${availableAttrs.length > 0 ? availableAttrs.join(', ') + ', id' : 'id'}`,\n path,\n );\n }\n\n // Validate the value against the attribute type\n validateWhereClauseValue(value, dotPath, attrDef, startEntityName, path);\n};\n\nconst validateWhereClause = (\n whereClause: Record<string, unknown>,\n entityName: string,\n schema: IContainEntitiesAndLinks<any, any>,\n path: string,\n): void => {\n for (const [key, value] of Object.entries(whereClause)) {\n if (key === 'or' || key === 'and') {\n if (Array.isArray(value)) {\n for (const clause of value) {\n if (typeof clause === 'object' && clause !== null) {\n validateWhereClause(\n clause as Record<string, unknown>,\n entityName,\n schema,\n `${path}.${key}[${clause}]`,\n );\n }\n }\n }\n continue;\n }\n\n if (key === 'id') {\n validateWhereClauseValue(\n value,\n 'id',\n new DataAttrDef('string', false, true),\n entityName,\n `${path}.id`,\n );\n continue;\n }\n\n if (key.includes('.')) {\n validateDotNotationAttribute(\n key,\n value,\n entityName,\n schema,\n `${path}.${key}`,\n );\n continue;\n }\n\n const entityDef = schema.entities[entityName];\n if (!entityDef) continue;\n\n const attrDef = entityDef.attrs[key];\n const linkDef = entityDef.links[key];\n\n if (!attrDef && !linkDef) {\n const availableAttrs = Object.keys(entityDef.attrs);\n const availableLinks = Object.keys(entityDef.links);\n throw new QueryValidationError(\n `Attribute or link '${key}' does not exist on entity '${entityName}'. Available attributes: ${availableAttrs.length > 0 ? availableAttrs.join(', ') : 'none'}. Available links: ${availableLinks.length > 0 ? availableLinks.join(', ') : 'none'}`,\n `${path}.${key}`,\n );\n }\n\n if (attrDef) {\n validateWhereClauseValue(\n value,\n key,\n attrDef,\n entityName,\n `${path}.${key}`,\n );\n } else if (linkDef) {\n // For links, we expect the value to be a string (ID of the linked entity)\n // Create a synthetic string attribute definition for validation\n if (typeof value === 'string' && !validateUUID(value)) {\n throw new QueryValidationError(\n `Invalid value for link '${key}' in entity '${entityName}'. Expected a UUID, but received: ${value}`,\n `${path}.${key}`,\n );\n }\n const syntheticAttrDef = new DataAttrDef('string', false, true);\n validateWhereClauseValue(\n value,\n key,\n syntheticAttrDef,\n entityName,\n `${path}.${key}`,\n );\n }\n }\n};\n\nconst validateDollarObject = (\n dollarObj: Record<string, unknown>,\n entityName: string,\n schema?: IContainEntitiesAndLinks<any, any> | null | undefined,\n path?: string,\n depth: number = 0,\n): void => {\n for (const key of Object.keys(dollarObj)) {\n if (!dollarSignKeys.includes(key)) {\n throw new QueryValidationError(\n `Invalid query parameter '${key}' in $ object. Valid parameters are: ${dollarSignKeys.join(', ')}. Found: ${key}`,\n path,\n );\n }\n }\n\n // Validate that pagination parameters are only used at top-level\n const paginationParams = [\n // 'limit', // only supported client side\n 'offset',\n 'before',\n 'after',\n 'first',\n 'last',\n ];\n for (const param of paginationParams) {\n if (dollarObj[param] !== undefined && depth > 0) {\n throw new QueryValidationError(\n `'${param}' can only be used on top-level namespaces. It cannot be used in nested queries.`,\n path,\n );\n }\n }\n\n if (dollarObj.where && schema) {\n if (typeof dollarObj.where !== 'object' || dollarObj.where === null) {\n throw new QueryValidationError(\n `'where' clause must be an object in entity '${entityName}', but received: ${typeof dollarObj.where}`,\n path ? `${path}.where` : undefined,\n );\n }\n validateWhereClause(\n dollarObj.where as Record<string, unknown>,\n entityName,\n schema,\n path ? `${path}.where` : 'where',\n );\n }\n};\n\nconst validateEntityInQuery = (\n queryPart: Record<string, unknown>,\n entityName: string,\n schema: IContainEntitiesAndLinks<any, any> | null | undefined,\n path: string,\n depth: number = 0,\n): void => {\n if (!queryPart || typeof queryPart !== 'object') {\n throw new QueryValidationError(\n `Query part for entity '${entityName}' must be an object, but received: ${typeof queryPart}`,\n path,\n );\n }\n\n for (const key of Object.keys(queryPart)) {\n if (key !== '$') {\n // Validate link exists\n if (schema && !(key in schema.entities[entityName].links)) {\n const availableLinks = Object.keys(schema.entities[entityName].links);\n throw new QueryValidationError(\n `Link '${key}' does not exist on entity '${entityName}'. Available links: ${availableLinks.length > 0 ? availableLinks.join(', ') : 'none'}`,\n `${path}.${key}`,\n );\n }\n\n // Recursively validate nested query\n const nestedQuery = queryPart[key];\n if (typeof nestedQuery === 'object' && nestedQuery !== null) {\n const linkedEntityName =\n schema?.entities[entityName].links[key]?.entityName;\n if (linkedEntityName) {\n validateEntityInQuery(\n nestedQuery as Record<string, unknown>,\n linkedEntityName,\n schema,\n `${path}.${key}`,\n depth + 1,\n );\n }\n }\n } else {\n // Validate $ object\n const dollarObj = queryPart[key];\n if (typeof dollarObj !== 'object' || dollarObj === null) {\n throw new QueryValidationError(\n `Query parameter '$' must be an object in entity '${entityName}', but received: ${typeof dollarObj}`,\n `${path}.$`,\n );\n }\n\n validateDollarObject(\n dollarObj as Record<string, unknown>,\n entityName,\n schema,\n `${path}.$`,\n depth,\n );\n }\n }\n};\n\nexport const validateQuery = (\n q: unknown,\n schema?: IContainEntitiesAndLinks<any, any>,\n): void => {\n if (typeof q !== 'object' || q === null) {\n throw new QueryValidationError(\n `Query must be an object, but received: ${typeof q}${q === null ? ' (null)' : ''}`,\n );\n }\n\n if (Array.isArray(q)) {\n throw new QueryValidationError(\n `Query must be an object, but received: ${typeof q}`,\n );\n }\n\n const queryObj = q as Record<string, unknown>;\n\n for (const topLevelKey of Object.keys(queryObj)) {\n if (Array.isArray(q[topLevelKey])) {\n throw new QueryValidationError(\n `Query keys must be strings, but found key of type: ${typeof topLevelKey}`,\n topLevelKey,\n );\n }\n\n if (typeof topLevelKey !== 'string') {\n throw new QueryValidationError(\n `Query keys must be strings, but found key of type: ${typeof topLevelKey}`,\n topLevelKey,\n );\n }\n\n if (topLevelKey === '$$ruleParams') {\n continue;\n }\n\n // Check if the key is top level entity\n if (schema) {\n if (!schema.entities[topLevelKey]) {\n const availableEntities = Object.keys(schema.entities);\n throw new QueryValidationError(\n `Entity '${topLevelKey}' does not exist in schema. Available entities: ${availableEntities.length > 0 ? availableEntities.join(', ') : 'none'}`,\n topLevelKey,\n );\n }\n }\n\n validateEntityInQuery(\n queryObj[topLevelKey] as Record<string, unknown>,\n topLevelKey,\n schema,\n topLevelKey,\n 0, // Start at depth 0 for top-level entities\n );\n }\n};\n"]}
@@ -63,11 +63,10 @@ function any() {
63
63
  // ==========
64
64
  // internal
65
65
  function enrichEntitiesWithLinks(entities, links) {
66
- var _a, _b, _c, _d;
67
66
  const linksIndex = { fwd: {}, rev: {} };
68
67
  for (const linkDef of Object.values(links)) {
69
- (_a = linksIndex.fwd)[_b = linkDef.forward.on] || (_a[_b] = {});
70
- (_c = linksIndex.rev)[_d = linkDef.reverse.on] || (_c[_d] = {});
68
+ linksIndex.fwd[linkDef.forward.on] ||= {};
69
+ linksIndex.rev[linkDef.reverse.on] ||= {};
71
70
  linksIndex.fwd[linkDef.forward.on][linkDef.forward.label] = {
72
71
  entityName: linkDef.reverse.on,
73
72
  cardinality: linkDef.forward.has,
@@ -79,7 +78,10 @@ function enrichEntitiesWithLinks(entities, links) {
79
78
  }
80
79
  const enrichedEntities = Object.fromEntries(Object.entries(entities).map(([name, def]) => [
81
80
  name,
82
- new EntityDef(def.attrs, Object.assign(Object.assign({}, linksIndex.fwd[name]), linksIndex.rev[name])),
81
+ new EntityDef(def.attrs, {
82
+ ...linksIndex.fwd[name],
83
+ ...linksIndex.rev[name],
84
+ }),
83
85
  ]));
84
86
  return enrichedEntities;
85
87
  }
@@ -101,8 +103,8 @@ function enrichEntitiesWithLinks(entities, links) {
101
103
  * });
102
104
  */
103
105
  function schema({ entities, links, rooms, }) {
104
- const linksDef = (links !== null && links !== void 0 ? links : {});
105
- const roomsDef = (rooms !== null && rooms !== void 0 ? rooms : {});
106
+ const linksDef = (links ?? {});
107
+ const roomsDef = (rooms ?? {});
106
108
  return new InstantSchemaDef(enrichEntitiesWithLinks(entities, linksDef),
107
109
  // (XXX): LinksDef<any> stems from TypeScript's inability to reconcile the
108
110
  // type EntitiesWithLinks<EntitiesWithoutLinks, Links> with
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":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AM,QAAQ,GAAG,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAU,CAAC;IACxC,MAAM,QAAQ,GAAG,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAU,CAAC;IACxC,OAAO,IAAI,gBAAgB,CACzB,uBAAuB,CAA8B,QAAQ,EAAE,QAAQ,CAAC;IACxE,0EAA0E;IAC1E,2DAA2D;IAC3D,2EAA2E;IAC3E,0EAA0E;IAC1E,4CAA4C;IAC5C,QAAyB,EACzB,QAAQ,CACT,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,CAAC,GAAG;IACf,aAAa;IACb,KAAK;IACL,MAAM;IACN,MAAM;IACN,cAAc;IACd,MAAM;IACN,MAAM;IACN,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,GAAG;CACJ,CAAC","sourcesContent":["import {\n EntityDef,\n DataAttrDef,\n InstantSchemaDef,\n type EntitiesDef,\n type AttrsDefs,\n type EntitiesWithLinks,\n type LinksDef,\n type RoomsDef,\n type UnknownRooms,\n} from './schemaTypes.ts';\n\n// ==========\n// API\n\n/**\n * @deprecated\n * `i.graph` is deprecated. Use `i.schema` instead.\n *\n * @example\n * // Before\n * i.graph(entities, links).withRoomSchema<RoomType>();\n *\n * // After\n * i.schema({ entities, links, rooms })\n *\n * @see\n * https://instantdb.com/docs/modeling-data\n */\nfunction graph<\n EntitiesWithoutLinks extends EntitiesDef,\n const Links extends LinksDef<EntitiesWithoutLinks>,\n>(entities: EntitiesWithoutLinks, links: Links) {\n return new InstantSchemaDef(\n enrichEntitiesWithLinks<EntitiesWithoutLinks, Links>(entities, links),\n // (XXX): LinksDef<any> stems from TypeScript’s inability to reconcile the\n // type EntitiesWithLinks<EntitiesWithoutLinks, Links> with\n // EntitiesWithoutLinks. TypeScript is strict about ensuring that types are\n // correctly aligned and does not allow for substituting a type that might\n // be broader or have additional properties.\n links as LinksDef<any>,\n undefined as unknown as UnknownRooms,\n );\n}\n\n/**\n * Creates an entity definition, to be used in conjunction with `i.graph`.\n *\n * @see https://instantdb.com/docs/modeling-data\n * @example\n * {\n * posts: i.entity({\n * title: i.string(),\n * body: i.string(),\n * }),\n * comments: i.entity({\n * body: i.string(),\n * })\n * }\n */\nfunction entity<Attrs extends AttrsDefs>(\n attrs: Attrs,\n): EntityDef<Attrs, {}, void> {\n return new EntityDef(attrs, {});\n}\n\nfunction string<StringEnum extends string = string>(): DataAttrDef<\n StringEnum,\n true,\n false\n> {\n return new DataAttrDef('string', true, false);\n}\n\nfunction number(): DataAttrDef<number, true, false> {\n return new DataAttrDef('number', true, false);\n}\n\nfunction boolean(): DataAttrDef<boolean, true, false> {\n return new DataAttrDef('boolean', true, false);\n}\n\nfunction date(): DataAttrDef<Date, true, false> {\n return new DataAttrDef('date', true, false);\n}\n\nfunction json<T = any>(): DataAttrDef<T, true, false> {\n return new DataAttrDef('json', true, false);\n}\n\nfunction any(): DataAttrDef<any, true, false> {\n return new DataAttrDef('json', true, false);\n}\n\n// ==========\n// internal\n\nfunction enrichEntitiesWithLinks<\n EntitiesWithoutLinks extends EntitiesDef,\n Links extends LinksDef<any>,\n EnrichedEntities = EntitiesWithLinks<EntitiesWithoutLinks, Links>,\n>(entities: EntitiesWithoutLinks, links: Links): EnrichedEntities {\n const linksIndex: LinksIndex = { fwd: {}, rev: {} };\n\n for (const linkDef of Object.values(links)) {\n linksIndex.fwd[linkDef.forward.on as string] ||= {};\n linksIndex.rev[linkDef.reverse.on as string] ||= {};\n\n linksIndex.fwd[linkDef.forward.on as string][linkDef.forward.label] = {\n entityName: linkDef.reverse.on as string,\n cardinality: linkDef.forward.has,\n };\n\n linksIndex.rev[linkDef.reverse.on as string][linkDef.reverse.label] = {\n entityName: linkDef.forward.on as string,\n cardinality: linkDef.reverse.has,\n };\n }\n\n const enrichedEntities = Object.fromEntries(\n Object.entries(entities).map(([name, def]) => [\n name,\n new EntityDef(def.attrs, {\n ...linksIndex.fwd[name],\n ...linksIndex.rev[name],\n }),\n ]),\n );\n\n return enrichedEntities as EnrichedEntities;\n}\n\ntype LinksIndex = Record<\n 'fwd' | 'rev',\n Record<string, Record<string, { entityName: string; cardinality: string }>>\n>;\n\n/**\n * Lets you define a schema for your database.\n *\n * You can define entities, links between entities, and if you use\n * presence, you can define rooms.\n *\n * You can push this schema to your database with the CLI,\n * or use it inside `init`, to get typesafety and autocompletion.\n *\n * @see https://instantdb.com/docs/modeling-data\n * @example\n * i.schema({\n * entities: { },\n * links: { },\n * rooms: { }\n * });\n */\nfunction schema<\n EntitiesWithoutLinks extends EntitiesDef,\n const Links extends LinksDef<EntitiesWithoutLinks>,\n Rooms extends RoomsDef = {},\n>({\n entities,\n links,\n rooms,\n}: {\n entities: EntitiesWithoutLinks;\n links?: Links;\n rooms?: Rooms;\n}) {\n const linksDef = (links ?? {}) as Links;\n const roomsDef = (rooms ?? {}) as Rooms;\n return new InstantSchemaDef(\n enrichEntitiesWithLinks<EntitiesWithoutLinks, Links>(entities, linksDef),\n // (XXX): LinksDef<any> stems from TypeScript's inability to reconcile the\n // type EntitiesWithLinks<EntitiesWithoutLinks, Links> with\n // EntitiesWithoutLinks. TypeScript is strict about ensuring that types are\n // correctly aligned and does not allow for substituting a type that might\n // be broader or have additional properties.\n linksDef as LinksDef<any>,\n roomsDef,\n );\n}\n\nexport const i = {\n // constructs\n graph,\n schema,\n entity,\n // value types\n string,\n number,\n boolean,\n date,\n json,\n any,\n};\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,WAAW,EACX,gBAAgB,GAOjB,MAAM,kBAAkB,CAAC;AAE1B,aAAa;AACb,MAAM;AAEN;;;;;;;;;;;;;GAaG;AACH,SAAS,KAAK,CAGZ,QAA8B,EAAE,KAAY;IAC5C,OAAO,IAAI,gBAAgB,CACzB,uBAAuB,CAA8B,QAAQ,EAAE,KAAK,CAAC;IACrE,0EAA0E;IAC1E,2DAA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AyB,EACzB,QAAQ,CACT,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,CAAC,GAAG;IACf,aAAa;IACb,KAAK;IACL,MAAM;IACN,MAAM;IACN,cAAc;IACd,MAAM;IACN,MAAM;IACN,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,GAAG;CACJ,CAAC","sourcesContent":["import {\n EntityDef,\n DataAttrDef,\n InstantSchemaDef,\n type EntitiesDef,\n type AttrsDefs,\n type EntitiesWithLinks,\n type LinksDef,\n type RoomsDef,\n type UnknownRooms,\n} from './schemaTypes.ts';\n\n// ==========\n// API\n\n/**\n * @deprecated\n * `i.graph` is deprecated. Use `i.schema` instead.\n *\n * @example\n * // Before\n * i.graph(entities, links).withRoomSchema<RoomType>();\n *\n * // After\n * i.schema({ entities, links, rooms })\n *\n * @see\n * https://instantdb.com/docs/modeling-data\n */\nfunction graph<\n EntitiesWithoutLinks extends EntitiesDef,\n const Links extends LinksDef<EntitiesWithoutLinks>,\n>(entities: EntitiesWithoutLinks, links: Links) {\n return new InstantSchemaDef(\n enrichEntitiesWithLinks<EntitiesWithoutLinks, Links>(entities, links),\n // (XXX): LinksDef<any> stems from TypeScript’s inability to reconcile the\n // type EntitiesWithLinks<EntitiesWithoutLinks, Links> with\n // EntitiesWithoutLinks. TypeScript is strict about ensuring that types are\n // correctly aligned and does not allow for substituting a type that might\n // be broader or have additional properties.\n links as LinksDef<any>,\n undefined as unknown as UnknownRooms,\n );\n}\n\n/**\n * Creates an entity definition, to be used in conjunction with `i.graph`.\n *\n * @see https://instantdb.com/docs/modeling-data\n * @example\n * {\n * posts: i.entity({\n * title: i.string(),\n * body: i.string(),\n * }),\n * comments: i.entity({\n * body: i.string(),\n * })\n * }\n */\nfunction entity<Attrs extends AttrsDefs>(\n attrs: Attrs,\n): EntityDef<Attrs, {}, void> {\n return new EntityDef(attrs, {});\n}\n\nfunction string<StringEnum extends string = string>(): DataAttrDef<\n StringEnum,\n true,\n false\n> {\n return new DataAttrDef('string', true, false);\n}\n\nfunction number(): DataAttrDef<number, true, false> {\n return new DataAttrDef('number', true, false);\n}\n\nfunction boolean(): DataAttrDef<boolean, true, false> {\n return new DataAttrDef('boolean', true, false);\n}\n\nfunction date(): DataAttrDef<Date, true, false> {\n return new DataAttrDef('date', true, false);\n}\n\nfunction json<T = any>(): DataAttrDef<T, true, false> {\n return new DataAttrDef('json', true, false);\n}\n\nfunction any(): DataAttrDef<any, true, false> {\n return new DataAttrDef('json', true, false);\n}\n\n// ==========\n// internal\n\nfunction enrichEntitiesWithLinks<\n EntitiesWithoutLinks extends EntitiesDef,\n Links extends LinksDef<any>,\n EnrichedEntities = EntitiesWithLinks<EntitiesWithoutLinks, Links>,\n>(entities: EntitiesWithoutLinks, links: Links): EnrichedEntities {\n const linksIndex: LinksIndex = { fwd: {}, rev: {} };\n\n for (const linkDef of Object.values(links)) {\n linksIndex.fwd[linkDef.forward.on as string] ||= {};\n linksIndex.rev[linkDef.reverse.on as string] ||= {};\n\n linksIndex.fwd[linkDef.forward.on as string][linkDef.forward.label] = {\n entityName: linkDef.reverse.on as string,\n cardinality: linkDef.forward.has,\n };\n\n linksIndex.rev[linkDef.reverse.on as string][linkDef.reverse.label] = {\n entityName: linkDef.forward.on as string,\n cardinality: linkDef.reverse.has,\n };\n }\n\n const enrichedEntities = Object.fromEntries(\n Object.entries(entities).map(([name, def]) => [\n name,\n new EntityDef(def.attrs, {\n ...linksIndex.fwd[name],\n ...linksIndex.rev[name],\n }),\n ]),\n );\n\n return enrichedEntities as EnrichedEntities;\n}\n\ntype LinksIndex = Record<\n 'fwd' | 'rev',\n Record<string, Record<string, { entityName: string; cardinality: string }>>\n>;\n\n/**\n * Lets you define a schema for your database.\n *\n * You can define entities, links between entities, and if you use\n * presence, you can define rooms.\n *\n * You can push this schema to your database with the CLI,\n * or use it inside `init`, to get typesafety and autocompletion.\n *\n * @see https://instantdb.com/docs/modeling-data\n * @example\n * i.schema({\n * entities: { },\n * links: { },\n * rooms: { }\n * });\n */\nfunction schema<\n EntitiesWithoutLinks extends EntitiesDef,\n const Links extends LinksDef<EntitiesWithoutLinks>,\n Rooms extends RoomsDef = {},\n>({\n entities,\n links,\n rooms,\n}: {\n entities: EntitiesWithoutLinks;\n links?: Links;\n rooms?: Rooms;\n}) {\n const linksDef = (links ?? {}) as Links;\n const roomsDef = (rooms ?? {}) as Rooms;\n return new InstantSchemaDef(\n enrichEntitiesWithLinks<EntitiesWithoutLinks, Links>(entities, linksDef),\n // (XXX): LinksDef<any> stems from TypeScript's inability to reconcile the\n // type EntitiesWithLinks<EntitiesWithoutLinks, Links> with\n // EntitiesWithoutLinks. TypeScript is strict about ensuring that types are\n // correctly aligned and does not allow for substituting a type that might\n // be broader or have additional properties.\n linksDef as LinksDef<any>,\n roomsDef,\n );\n}\n\nexport const i = {\n // constructs\n graph,\n schema,\n entity,\n // value types\n string,\n number,\n boolean,\n date,\n json,\n any,\n};\n"]}
@@ -1,10 +1,14 @@
1
1
  export class DataAttrDef {
2
+ valueType;
3
+ required;
4
+ isIndexed;
5
+ config;
6
+ metadata = {};
2
7
  constructor(valueType, required, isIndexed, config = { indexed: false, unique: false }) {
3
8
  this.valueType = valueType;
4
9
  this.required = required;
5
10
  this.isIndexed = isIndexed;
6
11
  this.config = config;
7
- this.metadata = {};
8
12
  }
9
13
  /**
10
14
  * @deprecated Only use this temporarily for attributes that you want
@@ -18,19 +22,29 @@ export class DataAttrDef {
18
22
  return new DataAttrDef(this.valueType, false, this.isIndexed, this.config);
19
23
  }
20
24
  unique() {
21
- return new DataAttrDef(this.valueType, this.required, this.isIndexed, Object.assign(Object.assign({}, this.config), { unique: true }));
25
+ return new DataAttrDef(this.valueType, this.required, this.isIndexed, {
26
+ ...this.config,
27
+ unique: true,
28
+ });
22
29
  }
23
30
  indexed() {
24
- return new DataAttrDef(this.valueType, this.required, true, Object.assign(Object.assign({}, this.config), { indexed: true }));
31
+ return new DataAttrDef(this.valueType, this.required, true, {
32
+ ...this.config,
33
+ indexed: true,
34
+ });
25
35
  }
26
36
  }
27
37
  export class LinkAttrDef {
38
+ cardinality;
39
+ entityName;
28
40
  constructor(cardinality, entityName) {
29
41
  this.cardinality = cardinality;
30
42
  this.entityName = entityName;
31
43
  }
32
44
  }
33
45
  export class EntityDef {
46
+ attrs;
47
+ links;
34
48
  constructor(attrs, links) {
35
49
  this.attrs = attrs;
36
50
  this.links = links;
@@ -40,6 +54,9 @@ export class EntityDef {
40
54
  }
41
55
  }
42
56
  export class InstantSchemaDef {
57
+ entities;
58
+ links;
59
+ rooms;
43
60
  constructor(entities, links, rooms) {
44
61
  this.entities = entities;
45
62
  this.links = links;
@@ -75,6 +92,8 @@ export class InstantSchemaDef {
75
92
  * @see https://instantdb.com/docs/modeling-data
76
93
  */
77
94
  export class InstantGraph {
95
+ entities;
96
+ links;
78
97
  constructor(entities, links) {
79
98
  this.entities = entities;
80
99
  this.links = links;
@@ -1 +1 @@
1
- {"version":3,"file":"schemaTypes.js","sourceRoot":"","sources":["../../src/schemaTypes.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,WAAW;IAOtB,YACS,SAAqB,EACrB,QAAoB,EACpB,SAAoB,EAEpB,SAIH,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;QAR9B,cAAS,GAAT,SAAS,CAAY;QACrB,aAAQ,GAAR,QAAQ,CAAY;QACpB,cAAS,GAAT,SAAS,CAAW;QAEpB,WAAM,GAAN,MAAM,CAIwB;QAXhC,aAAQ,GAA4B,EAAE,CAAC;IAY3C,CAAC;IAEJ;;;;OAIG;IACH,cAAc;QACZ,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,SAAS,EACd,KAAwB,EACxB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,MAAM,CACZ,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,SAAS,EACd,KAAK,EACL,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,MAAM,CACZ,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cAAc;QACZ,OAAO,IAAI,YAAY,CACrB,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,KAAK,CACX,CAAC;IACJ,CAAC;CACF;AAqGD,MAAM,OAAO,uBAAwB,SAAQ,gBAI5C;CAAG","sourcesContent":["import type { RoomSchemaShape } from './presence.ts';\nimport { Expand } from './queryTypes.ts';\n\nexport class DataAttrDef<\n ValueType,\n IsRequired extends RequirementKind,\n IsIndexed extends boolean,\n> {\n public metadata: Record<string, unknown> = {};\n\n constructor(\n public valueType: ValueTypes,\n public required: IsRequired,\n public isIndexed: IsIndexed,\n\n public config: {\n indexed: boolean;\n unique: boolean;\n // clientValidator?: (value: ValueType) => boolean;\n } = { indexed: false, unique: false },\n ) {}\n\n /**\n * @deprecated Only use this temporarily for attributes that you want\n * to treat as required in frontend code but can’t yet mark as required\n * and enforced for backend\n */\n clientRequired() {\n return new DataAttrDef<ValueType, true, IsIndexed>(\n this.valueType,\n false as unknown as true,\n this.isIndexed,\n this.config,\n );\n }\n\n optional() {\n return new DataAttrDef<ValueType, false, IsIndexed>(\n this.valueType,\n false,\n this.isIndexed,\n this.config,\n );\n }\n\n unique() {\n return new DataAttrDef<ValueType, IsRequired, IsIndexed>(\n this.valueType,\n this.required,\n this.isIndexed,\n {\n ...this.config,\n unique: true,\n },\n );\n }\n\n indexed() {\n return new DataAttrDef<ValueType, IsRequired, true>(\n this.valueType,\n this.required,\n true,\n {\n ...this.config,\n indexed: true,\n },\n );\n }\n\n // clientValidate(clientValidator: (value: ValueType) => boolean) {\n // return new DataAttrDef(this.valueType, this.required, {\n // ...this.config,\n // clientValidator,\n // });\n // }\n}\n\nexport class LinkAttrDef<\n Cardinality extends CardinalityKind,\n EntityName extends string,\n> {\n constructor(\n public cardinality: Cardinality,\n public entityName: EntityName,\n ) {}\n}\n\nexport interface IContainEntitiesAndLinks<\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n> {\n entities: Entities;\n links: Links;\n}\n\n// ==========\n// base types\n\nexport type ValueTypes = 'string' | 'number' | 'boolean' | 'date' | 'json';\n\nexport type CardinalityKind = 'one' | 'many';\n\n// true - force required\n// false - optional, not required\nexport type RequirementKind = true | false;\n\nexport type AttrsDefs = Record<string, DataAttrDef<any, any, any>>;\n\nexport class EntityDef<\n Attrs extends AttrsDefs,\n Links extends Record<string, LinkAttrDef<any, any>>,\n AsType,\n> {\n constructor(\n public attrs: Attrs,\n public links: Links,\n ) {}\n\n asType<_AsType extends Partial<MappedAttrs<Attrs, boolean>>>() {\n return new EntityDef<Attrs, Links, _AsType>(this.attrs, this.links);\n }\n}\n\nexport type EntityDefFromSchema<\n S extends IContainEntitiesAndLinks<any, any>,\n K extends keyof S['entities'],\n> = {\n [k in keyof S['entities'][K]['attrs']]: S['entities'][K] extends EntityDef<\n any,\n any,\n any\n >\n ? S['entities'][K]['attrs'][k]\n : never;\n};\n\nexport type EntitiesDef = Record<string, EntityDef<any, any, any>>;\n\nexport type LinksDef<Entities extends EntitiesDef> = Record<\n string,\n LinkDef<\n Entities,\n keyof Entities,\n string,\n CardinalityKind,\n keyof Entities,\n string,\n CardinalityKind\n >\n>;\n\nexport type LinkDef<\n Entities extends EntitiesDef,\n FwdEntity extends keyof Entities,\n FwdAttr extends string,\n FwdCardinality extends CardinalityKind,\n RevEntity extends keyof Entities,\n RevAttr extends string,\n RevCardinality extends CardinalityKind,\n> = {\n forward: {\n on: FwdEntity;\n label: FwdAttr;\n has: FwdCardinality;\n required?: RequirementKind;\n onDelete?: 'cascade';\n };\n reverse: {\n on: RevEntity;\n label: RevAttr;\n has: RevCardinality;\n onDelete?: 'cascade';\n };\n};\n\n// ==========\n// derived types\ntype IsEmptyOrIndexSignature<T> = keyof T extends never\n ? true\n : string extends keyof T\n ? true\n : false;\n\nexport type EntitiesWithLinks<\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n> = {\n [EntityName in keyof Entities]: EntityDef<\n Entities[EntityName]['attrs'],\n EntityForwardLinksMap<EntityName, Entities, Links> &\n EntityReverseLinksMap<EntityName, Entities, Links>,\n Entities[EntityName] extends EntityDef<any, any, infer O>\n ? O extends void\n ? void\n : O\n : void\n >;\n};\n\ntype EntityForwardLinksMap<\n EntityName extends keyof Entities,\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n LinkIndexFwd = LinksIndexedByEntity<Entities, Links, 'reverse'>,\n> =\n IsEmptyOrIndexSignature<Links> extends true\n ? {}\n : EntityName extends keyof LinkIndexFwd\n ? {\n [LinkName in keyof LinkIndexFwd[EntityName]]: LinkIndexFwd[EntityName][LinkName] extends LinkDef<\n Entities,\n infer RelatedEntityName,\n any,\n any,\n any,\n any,\n infer Cardinality\n >\n ? {\n entityName: RelatedEntityName;\n cardinality: Cardinality;\n }\n : never;\n }\n : {};\n\ntype EntityReverseLinksMap<\n EntityName extends keyof Entities,\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n RevLinkIndex = LinksIndexedByEntity<Entities, Links, 'forward'>,\n> =\n IsEmptyOrIndexSignature<Links> extends true\n ? {}\n : EntityName extends keyof RevLinkIndex\n ? {\n [LinkName in keyof RevLinkIndex[EntityName]]: RevLinkIndex[EntityName][LinkName] extends LinkDef<\n Entities,\n any,\n any,\n infer Cardinality,\n infer RelatedEntityName,\n any,\n any\n >\n ? {\n entityName: RelatedEntityName;\n cardinality: Cardinality;\n }\n : never;\n }\n : {};\n\ntype LinksIndexedByEntity<\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n Direction extends 'forward' | 'reverse',\n> = {\n [FwdEntity in keyof Entities]: {\n [LinkName in keyof Links as Links[LinkName][Direction]['on'] extends FwdEntity\n ? Links[LinkName][Direction]['label']\n : never]: Links[LinkName] extends LinkDef<\n Entities,\n infer FwdEntity,\n infer FwdAttr,\n infer FwdCardinality,\n infer RevEntity,\n infer RevAttr,\n infer RevCardinality\n >\n ? LinkDef<\n Entities,\n FwdEntity,\n FwdAttr,\n FwdCardinality,\n RevEntity,\n RevAttr,\n RevCardinality\n >\n : never;\n };\n};\n\ntype RequiredKeys<Attrs extends AttrsDefs> = {\n [K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, infer R, any>\n ? R extends true\n ? K\n : never\n : never;\n}[keyof Attrs];\n\ntype OptionalKeys<Attrs extends AttrsDefs> = {\n [K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, infer R, any>\n ? R extends false\n ? K\n : never\n : never;\n}[keyof Attrs];\n\n/**\n * MappedAttrs:\n * - Required keys => `key: ValueType`\n * - Optional keys => `key?: ValueType`\n */\ntype MappedAttrs<Attrs extends AttrsDefs, UseDates extends boolean> = {\n [K in RequiredKeys<Attrs>]: Attrs[K] extends DataAttrDef<infer V, any, any>\n ? V extends Date\n ? UseDates extends true\n ? V\n : string | number\n : V\n : never;\n} & {\n [K in OptionalKeys<Attrs>]?: Attrs[K] extends DataAttrDef<infer V, any, any>\n ? V extends Date\n ? UseDates extends true\n ? V\n : string | number\n : V\n : never;\n};\n\nexport type ResolveEntityAttrs<\n EDef extends EntityDef<any, any, any>,\n UseDates extends boolean = false,\n ResolvedAttrs = MappedAttrs<EDef['attrs'], UseDates>,\n> =\n EDef extends EntityDef<any, any, infer AsType>\n ? AsType extends void\n ? ResolvedAttrs\n : Omit<ResolvedAttrs, keyof AsType> & AsType\n : ResolvedAttrs;\n\nexport type ResolveAttrs<\n Entities extends EntitiesDef,\n EntityName extends keyof Entities,\n UseDates extends boolean,\n> = ResolveEntityAttrs<Entities[EntityName], UseDates>;\n\nexport type RoomsFromDef<RDef extends RoomsDef> = {\n [RoomName in keyof RDef]: {\n presence: Expand<ResolveEntityAttrs<RDef[RoomName]['presence']>>;\n topics: {\n [TopicName in keyof RDef[RoomName]['topics']]: Expand<\n ResolveEntityAttrs<NonNullable<RDef[RoomName]['topics']>[TopicName]>\n >;\n };\n };\n};\n\nexport type RoomsOf<S> =\n S extends InstantSchemaDef<any, any, infer RDef> ? RoomsFromDef<RDef> : never;\n\nexport type PresenceOf<\n S,\n RoomType extends keyof RoomsOf<S>,\n> = RoomsOf<S>[RoomType] extends { presence: infer P } ? P : {};\n\nexport type TopicsOf<\n S,\n RoomType extends keyof RoomsOf<S>,\n> = RoomsOf<S>[RoomType] extends { topics: infer T } ? T : {};\n\nexport type TopicOf<\n S,\n RoomType extends keyof RoomsOf<S>,\n TopicType extends keyof TopicsOf<S, RoomType>,\n> = TopicsOf<S, RoomType>[TopicType];\n\ninterface RoomDef {\n presence: EntityDef<any, any, any>;\n topics?: {\n [TopicName: string]: EntityDef<any, any, any>;\n };\n}\n\nexport interface RoomsDef {\n [RoomType: string]: RoomDef;\n}\n\nexport class InstantSchemaDef<\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n Rooms extends RoomsDef,\n> implements IContainEntitiesAndLinks<Entities, Links>\n{\n constructor(\n public entities: Entities,\n public links: Links,\n public rooms: Rooms,\n ) {}\n\n /**\n * @deprecated\n * `withRoomSchema` is deprecated. Define your schema in `rooms` directly:\n *\n * @example\n * // Before:\n * const schema = i.schema({\n * // ...\n * }).withRoomSchema<RoomSchema>()\n *\n * // After\n * const schema = i.schema({\n * rooms: {\n * // ...\n * }\n * })\n *\n * @see https://instantdb.com/docs/presence-and-topics#typesafety\n */\n withRoomSchema<_RoomSchema extends RoomSchemaShape>() {\n type RDef = RoomDefFromShape<_RoomSchema>;\n return new InstantSchemaDef<Entities, Links, RDef>(\n this.entities,\n this.links,\n {} as RDef,\n );\n }\n}\n\n/**\n * @deprecated\n * `i.graph` is deprecated. Use `i.schema` instead.\n *\n * @see https://instantdb.com/docs/modeling-data\n */\nexport class InstantGraph<\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n RoomSchema extends RoomSchemaShape = {},\n> implements IContainEntitiesAndLinks<Entities, Links>\n{\n constructor(\n public entities: Entities,\n public links: Links,\n ) {}\n\n withRoomSchema<_RoomSchema extends RoomSchemaShape>() {\n return new InstantGraph<Entities, Links, _RoomSchema>(\n this.entities,\n this.links,\n );\n }\n}\n\ntype EntityDefFromRoomSlice<Shape extends { [k: string]: any }> = EntityDef<\n {\n [AttrName in keyof Shape]: DataAttrDef<\n Shape[AttrName],\n Shape[AttrName] extends undefined ? false : true,\n any\n >;\n },\n any,\n void\n>;\n\ntype RoomDefFromShape<RoomSchema extends RoomSchemaShape> = {\n [RoomName in keyof RoomSchema]: {\n presence: EntityDefFromRoomSlice<\n NonNullable<RoomSchema[RoomName]['presence']>\n >;\n topics: {\n [TopicName in keyof RoomSchema[RoomName]['topics']]: EntityDefFromRoomSlice<\n NonNullable<RoomSchema[RoomName]['topics'][TopicName]>\n >;\n };\n };\n};\n\ntype EntityDefFromShape<Shape, K extends keyof Shape> = EntityDef<\n {\n [AttrName in keyof Shape[K]]: DataAttrDef<\n Shape[K][AttrName],\n Shape[K][AttrName] extends undefined ? false : true,\n any\n >;\n },\n {\n [LinkName in keyof Shape]: LinkAttrDef<\n 'many',\n LinkName extends string ? LinkName : string\n >;\n },\n void\n>;\n\n/**\n * If you were using the old `schema` types, you can use this to help you\n * migrate.\n *\n * @example\n * // Before\n * const db = init<Schema, Rooms>({...})\n *\n * // After\n * const db = init<BackwardsCompatibleSchema<Schema, Rooms>>({...})\n */\nexport type BackwardsCompatibleSchema<\n Shape extends { [k: string]: any },\n RoomSchema extends RoomSchemaShape = {},\n> = InstantSchemaDef<\n { [K in keyof Shape]: EntityDefFromShape<Shape, K> },\n UnknownLinks<EntitiesDef>,\n RoomDefFromShape<RoomSchema>\n>;\n\n// ----------\n// InstantUnknownSchema\n\nexport type UnknownEntity = EntityDef<\n {\n id: DataAttrDef<string, true, true>;\n [AttrName: string]: DataAttrDef<any, boolean, boolean>;\n },\n { [LinkName: string]: LinkAttrDef<'many', string> },\n void\n>;\n\nexport type UnknownEntities = {\n [EntityName: string]: UnknownEntity;\n};\n\nexport interface UnknownLinks<Entities extends EntitiesDef> {\n [LinkName: string]: LinkDef<\n Entities,\n string,\n string,\n 'many',\n string,\n string,\n 'many'\n >;\n}\n\nexport interface UnknownRooms {\n [RoomName: string]: {\n presence: EntityDef<any, any, any>;\n topics: {\n [TopicName: string]: EntityDef<any, any, any>;\n };\n };\n}\n\nexport class InstantUnknownSchemaDef extends InstantSchemaDef<\n UnknownEntities,\n UnknownLinks<UnknownEntities>,\n UnknownRooms\n> {}\n\nexport type InstantUnknownSchema = InstantUnknownSchemaDef;\n\nexport type CreateParams<\n Schema extends IContainEntitiesAndLinks<any, any>,\n EntityName extends keyof Schema['entities'],\n> = {\n [AttrName in RequiredKeys<\n Schema['entities'][EntityName]['attrs']\n >]: Schema['entities'][EntityName]['attrs'][AttrName] extends DataAttrDef<\n infer ValueType,\n any,\n any\n >\n ? ValueType extends Date\n ? string | number | Date\n : ValueType\n : never;\n} & {\n [AttrName in OptionalKeys<\n Schema['entities'][EntityName]['attrs']\n >]?: Schema['entities'][EntityName]['attrs'][AttrName] extends DataAttrDef<\n infer ValueType,\n false,\n any\n >\n ? (ValueType extends Date ? string | number | Date : ValueType) | null\n : never;\n};\n\nexport type UpdateParams<\n Schema extends IContainEntitiesAndLinks<any, any>,\n EntityName extends keyof Schema['entities'],\n> = {\n [AttrName in keyof Schema['entities'][EntityName]['attrs']]?: Schema['entities'][EntityName]['attrs'][AttrName] extends DataAttrDef<\n infer ValueType,\n infer IsRequired,\n any\n >\n ? IsRequired extends true\n ? ValueType extends Date\n ? string | number | Date\n : ValueType\n : (ValueType extends Date ? string | number | Date : ValueType) | null\n : never;\n};\n\nexport type UpdateOpts = {\n upsert?: boolean | undefined;\n};\n\nexport type LinkParams<\n Schema extends IContainEntitiesAndLinks<any, any>,\n EntityName extends keyof Schema['entities'],\n> = {\n [LinkName in keyof Schema['entities'][EntityName]['links']]?: Schema['entities'][EntityName]['links'][LinkName] extends LinkAttrDef<\n infer Cardinality,\n any\n >\n ? Cardinality extends 'one'\n ? string\n : string | string[]\n : never;\n};\n\nexport type RuleParams = {\n [key: string]: any;\n};\n"]}
1
+ {"version":3,"file":"schemaTypes.js","sourceRoot":"","sources":["../../src/schemaTypes.ts"],"names":[],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AAL,KAAK,CAAO;QACZ,UAAK,GAAL,KAAK,CAAO;IAClB,CAAC;IAEJ,MAAM;QACJ,OAAO,IAAI,SAAS,CAAwB,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;IACtE,CAAC;CACF;AAmQD,MAAM,OAAO,gBAAgB;IAOlB;IACA;IACA;IAHT,YACS,QAAkB,EAClB,KAAY,EACZ,KAAY;QAFZ,aAAQ,GAAR,QAAQ,CAAU;QAClB,UAAK,GAAL,KAAK,CAAO;QACZ,UAAK,GAAL,KAAK,CAAO;IAClB,CAAC;IAEJ;;;;;;;;;;;;;;;;;;OAkBG;IACH,cAAc;QAEZ,OAAO,IAAI,gBAAgB,CACzB,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,KAAK,EACV,EAAU,CACX,CAAC;IACJ,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAOd;IACA;IAFT,YACS,QAAkB,EAClB,KAAY;QADZ,aAAQ,GAAR,QAAQ,CAAU;QAClB,UAAK,GAAL,KAAK,CAAO;IAClB,CAAC;IAEJ,cAAc;QACZ,OAAO,IAAI,YAAY,CACrB,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,KAAK,CACX,CAAC;IACJ,CAAC;CACF;AAqGD,MAAM,OAAO,uBAAwB,SAAQ,gBAI5C;CAAG","sourcesContent":["import type { RoomSchemaShape } from './presence.ts';\nimport { Expand } from './queryTypes.ts';\n\nexport class DataAttrDef<\n ValueType,\n IsRequired extends RequirementKind,\n IsIndexed extends boolean,\n> {\n public metadata: Record<string, unknown> = {};\n\n constructor(\n public valueType: ValueTypes,\n public required: IsRequired,\n public isIndexed: IsIndexed,\n\n public config: {\n indexed: boolean;\n unique: boolean;\n // clientValidator?: (value: ValueType) => boolean;\n } = { indexed: false, unique: false },\n ) {}\n\n /**\n * @deprecated Only use this temporarily for attributes that you want\n * to treat as required in frontend code but can’t yet mark as required\n * and enforced for backend\n */\n clientRequired() {\n return new DataAttrDef<ValueType, true, IsIndexed>(\n this.valueType,\n false as unknown as true,\n this.isIndexed,\n this.config,\n );\n }\n\n optional() {\n return new DataAttrDef<ValueType, false, IsIndexed>(\n this.valueType,\n false,\n this.isIndexed,\n this.config,\n );\n }\n\n unique() {\n return new DataAttrDef<ValueType, IsRequired, IsIndexed>(\n this.valueType,\n this.required,\n this.isIndexed,\n {\n ...this.config,\n unique: true,\n },\n );\n }\n\n indexed() {\n return new DataAttrDef<ValueType, IsRequired, true>(\n this.valueType,\n this.required,\n true,\n {\n ...this.config,\n indexed: true,\n },\n );\n }\n\n // clientValidate(clientValidator: (value: ValueType) => boolean) {\n // return new DataAttrDef(this.valueType, this.required, {\n // ...this.config,\n // clientValidator,\n // });\n // }\n}\n\nexport class LinkAttrDef<\n Cardinality extends CardinalityKind,\n EntityName extends string,\n> {\n constructor(\n public cardinality: Cardinality,\n public entityName: EntityName,\n ) {}\n}\n\nexport interface IContainEntitiesAndLinks<\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n> {\n entities: Entities;\n links: Links;\n}\n\n// ==========\n// base types\n\nexport type ValueTypes = 'string' | 'number' | 'boolean' | 'date' | 'json';\n\nexport type CardinalityKind = 'one' | 'many';\n\n// true - force required\n// false - optional, not required\nexport type RequirementKind = true | false;\n\nexport type AttrsDefs = Record<string, DataAttrDef<any, any, any>>;\n\nexport class EntityDef<\n Attrs extends AttrsDefs,\n Links extends Record<string, LinkAttrDef<any, any>>,\n AsType,\n> {\n constructor(\n public attrs: Attrs,\n public links: Links,\n ) {}\n\n asType<_AsType extends Partial<MappedAttrs<Attrs, boolean>>>() {\n return new EntityDef<Attrs, Links, _AsType>(this.attrs, this.links);\n }\n}\n\nexport type EntityDefFromSchema<\n S extends IContainEntitiesAndLinks<any, any>,\n K extends keyof S['entities'],\n> = {\n [k in keyof S['entities'][K]['attrs']]: S['entities'][K] extends EntityDef<\n any,\n any,\n any\n >\n ? S['entities'][K]['attrs'][k]\n : never;\n};\n\nexport type EntitiesDef = Record<string, EntityDef<any, any, any>>;\n\nexport type LinksDef<Entities extends EntitiesDef> = Record<\n string,\n LinkDef<\n Entities,\n keyof Entities,\n string,\n CardinalityKind,\n keyof Entities,\n string,\n CardinalityKind\n >\n>;\n\nexport type LinkDef<\n Entities extends EntitiesDef,\n FwdEntity extends keyof Entities,\n FwdAttr extends string,\n FwdCardinality extends CardinalityKind,\n RevEntity extends keyof Entities,\n RevAttr extends string,\n RevCardinality extends CardinalityKind,\n> = {\n forward: {\n on: FwdEntity;\n label: FwdAttr;\n has: FwdCardinality;\n required?: RequirementKind;\n onDelete?: 'cascade';\n };\n reverse: {\n on: RevEntity;\n label: RevAttr;\n has: RevCardinality;\n onDelete?: 'cascade';\n };\n};\n\n// ==========\n// derived types\ntype IsEmptyOrIndexSignature<T> = keyof T extends never\n ? true\n : string extends keyof T\n ? true\n : false;\n\nexport type EntitiesWithLinks<\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n> = {\n [EntityName in keyof Entities]: EntityDef<\n Entities[EntityName]['attrs'],\n EntityForwardLinksMap<EntityName, Entities, Links> &\n EntityReverseLinksMap<EntityName, Entities, Links>,\n Entities[EntityName] extends EntityDef<any, any, infer O>\n ? O extends void\n ? void\n : O\n : void\n >;\n};\n\ntype EntityForwardLinksMap<\n EntityName extends keyof Entities,\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n LinkIndexFwd = LinksIndexedByEntity<Entities, Links, 'reverse'>,\n> =\n IsEmptyOrIndexSignature<Links> extends true\n ? {}\n : EntityName extends keyof LinkIndexFwd\n ? {\n [LinkName in keyof LinkIndexFwd[EntityName]]: LinkIndexFwd[EntityName][LinkName] extends LinkDef<\n Entities,\n infer RelatedEntityName,\n any,\n any,\n any,\n any,\n infer Cardinality\n >\n ? {\n entityName: RelatedEntityName;\n cardinality: Cardinality;\n }\n : never;\n }\n : {};\n\ntype EntityReverseLinksMap<\n EntityName extends keyof Entities,\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n RevLinkIndex = LinksIndexedByEntity<Entities, Links, 'forward'>,\n> =\n IsEmptyOrIndexSignature<Links> extends true\n ? {}\n : EntityName extends keyof RevLinkIndex\n ? {\n [LinkName in keyof RevLinkIndex[EntityName]]: RevLinkIndex[EntityName][LinkName] extends LinkDef<\n Entities,\n any,\n any,\n infer Cardinality,\n infer RelatedEntityName,\n any,\n any\n >\n ? {\n entityName: RelatedEntityName;\n cardinality: Cardinality;\n }\n : never;\n }\n : {};\n\ntype LinksIndexedByEntity<\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n Direction extends 'forward' | 'reverse',\n> = {\n [FwdEntity in keyof Entities]: {\n [LinkName in keyof Links as Links[LinkName][Direction]['on'] extends FwdEntity\n ? Links[LinkName][Direction]['label']\n : never]: Links[LinkName] extends LinkDef<\n Entities,\n infer FwdEntity,\n infer FwdAttr,\n infer FwdCardinality,\n infer RevEntity,\n infer RevAttr,\n infer RevCardinality\n >\n ? LinkDef<\n Entities,\n FwdEntity,\n FwdAttr,\n FwdCardinality,\n RevEntity,\n RevAttr,\n RevCardinality\n >\n : never;\n };\n};\n\ntype RequiredKeys<Attrs extends AttrsDefs> = {\n [K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, infer R, any>\n ? R extends true\n ? K\n : never\n : never;\n}[keyof Attrs];\n\ntype OptionalKeys<Attrs extends AttrsDefs> = {\n [K in keyof Attrs]: Attrs[K] extends DataAttrDef<any, infer R, any>\n ? R extends false\n ? K\n : never\n : never;\n}[keyof Attrs];\n\n/**\n * MappedAttrs:\n * - Required keys => `key: ValueType`\n * - Optional keys => `key?: ValueType`\n */\ntype MappedAttrs<Attrs extends AttrsDefs, UseDates extends boolean> = {\n [K in RequiredKeys<Attrs>]: Attrs[K] extends DataAttrDef<infer V, any, any>\n ? V extends Date\n ? UseDates extends true\n ? V\n : string | number\n : V\n : never;\n} & {\n [K in OptionalKeys<Attrs>]?: Attrs[K] extends DataAttrDef<infer V, any, any>\n ? V extends Date\n ? UseDates extends true\n ? V\n : string | number\n : V\n : never;\n};\n\nexport type ResolveEntityAttrs<\n EDef extends EntityDef<any, any, any>,\n UseDates extends boolean = false,\n ResolvedAttrs = MappedAttrs<EDef['attrs'], UseDates>,\n> =\n EDef extends EntityDef<any, any, infer AsType>\n ? AsType extends void\n ? ResolvedAttrs\n : Omit<ResolvedAttrs, keyof AsType> & AsType\n : ResolvedAttrs;\n\nexport type ResolveAttrs<\n Entities extends EntitiesDef,\n EntityName extends keyof Entities,\n UseDates extends boolean,\n> = ResolveEntityAttrs<Entities[EntityName], UseDates>;\n\nexport type RoomsFromDef<RDef extends RoomsDef> = {\n [RoomName in keyof RDef]: {\n presence: Expand<ResolveEntityAttrs<RDef[RoomName]['presence']>>;\n topics: {\n [TopicName in keyof RDef[RoomName]['topics']]: Expand<\n ResolveEntityAttrs<NonNullable<RDef[RoomName]['topics']>[TopicName]>\n >;\n };\n };\n};\n\nexport type RoomsOf<S> =\n S extends InstantSchemaDef<any, any, infer RDef> ? RoomsFromDef<RDef> : never;\n\nexport type PresenceOf<\n S,\n RoomType extends keyof RoomsOf<S>,\n> = RoomsOf<S>[RoomType] extends { presence: infer P } ? P : {};\n\nexport type TopicsOf<\n S,\n RoomType extends keyof RoomsOf<S>,\n> = RoomsOf<S>[RoomType] extends { topics: infer T } ? T : {};\n\nexport type TopicOf<\n S,\n RoomType extends keyof RoomsOf<S>,\n TopicType extends keyof TopicsOf<S, RoomType>,\n> = TopicsOf<S, RoomType>[TopicType];\n\ninterface RoomDef {\n presence: EntityDef<any, any, any>;\n topics?: {\n [TopicName: string]: EntityDef<any, any, any>;\n };\n}\n\nexport interface RoomsDef {\n [RoomType: string]: RoomDef;\n}\n\nexport class InstantSchemaDef<\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n Rooms extends RoomsDef,\n> implements IContainEntitiesAndLinks<Entities, Links>\n{\n constructor(\n public entities: Entities,\n public links: Links,\n public rooms: Rooms,\n ) {}\n\n /**\n * @deprecated\n * `withRoomSchema` is deprecated. Define your schema in `rooms` directly:\n *\n * @example\n * // Before:\n * const schema = i.schema({\n * // ...\n * }).withRoomSchema<RoomSchema>()\n *\n * // After\n * const schema = i.schema({\n * rooms: {\n * // ...\n * }\n * })\n *\n * @see https://instantdb.com/docs/presence-and-topics#typesafety\n */\n withRoomSchema<_RoomSchema extends RoomSchemaShape>() {\n type RDef = RoomDefFromShape<_RoomSchema>;\n return new InstantSchemaDef<Entities, Links, RDef>(\n this.entities,\n this.links,\n {} as RDef,\n );\n }\n}\n\n/**\n * @deprecated\n * `i.graph` is deprecated. Use `i.schema` instead.\n *\n * @see https://instantdb.com/docs/modeling-data\n */\nexport class InstantGraph<\n Entities extends EntitiesDef,\n Links extends LinksDef<Entities>,\n RoomSchema extends RoomSchemaShape = {},\n> implements IContainEntitiesAndLinks<Entities, Links>\n{\n constructor(\n public entities: Entities,\n public links: Links,\n ) {}\n\n withRoomSchema<_RoomSchema extends RoomSchemaShape>() {\n return new InstantGraph<Entities, Links, _RoomSchema>(\n this.entities,\n this.links,\n );\n }\n}\n\ntype EntityDefFromRoomSlice<Shape extends { [k: string]: any }> = EntityDef<\n {\n [AttrName in keyof Shape]: DataAttrDef<\n Shape[AttrName],\n Shape[AttrName] extends undefined ? false : true,\n any\n >;\n },\n any,\n void\n>;\n\ntype RoomDefFromShape<RoomSchema extends RoomSchemaShape> = {\n [RoomName in keyof RoomSchema]: {\n presence: EntityDefFromRoomSlice<\n NonNullable<RoomSchema[RoomName]['presence']>\n >;\n topics: {\n [TopicName in keyof RoomSchema[RoomName]['topics']]: EntityDefFromRoomSlice<\n NonNullable<RoomSchema[RoomName]['topics'][TopicName]>\n >;\n };\n };\n};\n\ntype EntityDefFromShape<Shape, K extends keyof Shape> = EntityDef<\n {\n [AttrName in keyof Shape[K]]: DataAttrDef<\n Shape[K][AttrName],\n Shape[K][AttrName] extends undefined ? false : true,\n any\n >;\n },\n {\n [LinkName in keyof Shape]: LinkAttrDef<\n 'many',\n LinkName extends string ? LinkName : string\n >;\n },\n void\n>;\n\n/**\n * If you were using the old `schema` types, you can use this to help you\n * migrate.\n *\n * @example\n * // Before\n * const db = init<Schema, Rooms>({...})\n *\n * // After\n * const db = init<BackwardsCompatibleSchema<Schema, Rooms>>({...})\n */\nexport type BackwardsCompatibleSchema<\n Shape extends { [k: string]: any },\n RoomSchema extends RoomSchemaShape = {},\n> = InstantSchemaDef<\n { [K in keyof Shape]: EntityDefFromShape<Shape, K> },\n UnknownLinks<EntitiesDef>,\n RoomDefFromShape<RoomSchema>\n>;\n\n// ----------\n// InstantUnknownSchema\n\nexport type UnknownEntity = EntityDef<\n {\n id: DataAttrDef<string, true, true>;\n [AttrName: string]: DataAttrDef<any, boolean, boolean>;\n },\n { [LinkName: string]: LinkAttrDef<'many', string> },\n void\n>;\n\nexport type UnknownEntities = {\n [EntityName: string]: UnknownEntity;\n};\n\nexport interface UnknownLinks<Entities extends EntitiesDef> {\n [LinkName: string]: LinkDef<\n Entities,\n string,\n string,\n 'many',\n string,\n string,\n 'many'\n >;\n}\n\nexport interface UnknownRooms {\n [RoomName: string]: {\n presence: EntityDef<any, any, any>;\n topics: {\n [TopicName: string]: EntityDef<any, any, any>;\n };\n };\n}\n\nexport class InstantUnknownSchemaDef extends InstantSchemaDef<\n UnknownEntities,\n UnknownLinks<UnknownEntities>,\n UnknownRooms\n> {}\n\nexport type InstantUnknownSchema = InstantUnknownSchemaDef;\n\nexport type CreateParams<\n Schema extends IContainEntitiesAndLinks<any, any>,\n EntityName extends keyof Schema['entities'],\n> = {\n [AttrName in RequiredKeys<\n Schema['entities'][EntityName]['attrs']\n >]: Schema['entities'][EntityName]['attrs'][AttrName] extends DataAttrDef<\n infer ValueType,\n any,\n any\n >\n ? ValueType extends Date\n ? string | number | Date\n : ValueType\n : never;\n} & {\n [AttrName in OptionalKeys<\n Schema['entities'][EntityName]['attrs']\n >]?: Schema['entities'][EntityName]['attrs'][AttrName] extends DataAttrDef<\n infer ValueType,\n false,\n any\n >\n ? (ValueType extends Date ? string | number | Date : ValueType) | null\n : never;\n};\n\nexport type UpdateParams<\n Schema extends IContainEntitiesAndLinks<any, any>,\n EntityName extends keyof Schema['entities'],\n> = {\n [AttrName in keyof Schema['entities'][EntityName]['attrs']]?: Schema['entities'][EntityName]['attrs'][AttrName] extends DataAttrDef<\n infer ValueType,\n infer IsRequired,\n any\n >\n ? IsRequired extends true\n ? ValueType extends Date\n ? string | number | Date\n : ValueType\n : (ValueType extends Date ? string | number | Date : ValueType) | null\n : never;\n};\n\nexport type UpdateOpts = {\n upsert?: boolean | undefined;\n};\n\nexport type LinkParams<\n Schema extends IContainEntitiesAndLinks<any, any>,\n EntityName extends keyof Schema['entities'],\n> = {\n [LinkName in keyof Schema['entities'][EntityName]['links']]?: Schema['entities'][EntityName]['links'][LinkName] extends LinkAttrDef<\n infer Cardinality,\n any\n >\n ? Cardinality extends 'one'\n ? string\n : string | string[]\n : never;\n};\n\nexport type RuleParams = {\n [key: string]: any;\n};\n"]}
package/dist/esm/store.js CHANGED
@@ -2,11 +2,13 @@ import { create } from 'mutative';
2
2
  import { immutableDeepMerge } from './utils/object.js';
3
3
  import { coerceToDate } from "./utils/dates.js";
4
4
  export class AttrsStoreClass {
5
+ attrs;
6
+ linkIndex;
7
+ _blobAttrs = null;
8
+ _primaryKeys = null;
9
+ _forwardIdents = null;
10
+ _revIdents = null;
5
11
  constructor(attrs, linkIndex) {
6
- this._blobAttrs = null;
7
- this._primaryKeys = null;
8
- this._forwardIdents = null;
9
- this._revIdents = null;
10
12
  this.attrs = attrs;
11
13
  this.linkIndex = linkIndex;
12
14
  }
@@ -28,7 +30,7 @@ export class AttrsStoreClass {
28
30
  const attr = this.attrs[partialAttr.id];
29
31
  if (!attr)
30
32
  return;
31
- this.attrs[partialAttr.id] = Object.assign(Object.assign({}, attr), partialAttr);
33
+ this.attrs[partialAttr.id] = { ...attr, ...partialAttr };
32
34
  this.resetAttrIndexes();
33
35
  }
34
36
  getAttr(id) {
@@ -219,7 +221,6 @@ export function createStore(attrsStore, triples, enableCardinalityInference, use
219
221
  // then we drop the triple and have to wait for the server response
220
222
  // to see the optimistic updates.
221
223
  function resolveLookupRefs(store, triple) {
222
- var _a, _b;
223
224
  let eid;
224
225
  // Check if `e` is a lookup ref
225
226
  if (Array.isArray(triple[0])) {
@@ -232,7 +233,7 @@ function resolveLookupRefs(store, triple) {
232
233
  }
233
234
  // This would be a lot more efficient with a ave index
234
235
  const triples = allMapValues(eMaps, 2);
235
- eid = (_a = triples.find((x) => x[2] === v)) === null || _a === void 0 ? void 0 : _a[0];
236
+ eid = triples.find((x) => x[2] === v)?.[0];
236
237
  }
237
238
  else {
238
239
  eid = triple[0];
@@ -255,7 +256,7 @@ function resolveLookupRefs(store, triple) {
255
256
  return null;
256
257
  }
257
258
  const triples = allMapValues(eMaps, 2);
258
- const value = (_b = triples.find((x) => x[2] === v)) === null || _b === void 0 ? void 0 : _b[0];
259
+ const value = triples.find((x) => x[2] === v)?.[0];
259
260
  if (!value) {
260
261
  return null;
261
262
  }
@@ -315,7 +316,6 @@ function getCreatedAt(store, attr, triple) {
315
316
  return createdAt || Date.now() * 10 + _seed++;
316
317
  }
317
318
  export function addTriple(store, attrsStore, rawTriple) {
318
- var _a;
319
319
  const triple = resolveLookupRefs(store, rawTriple);
320
320
  if (!triple) {
321
321
  return;
@@ -336,7 +336,7 @@ export function addTriple(store, attrsStore, rawTriple) {
336
336
  // Reuse the created_at for a triple if it's already in the store.
337
337
  // Prevents updates from temporarily pushing an entity to the top
338
338
  // while waiting for the server response.
339
- const t = (_a = existingTriple === null || existingTriple === void 0 ? void 0 : existingTriple[3]) !== null && _a !== void 0 ? _a : getCreatedAt(store, attr, triple);
339
+ const t = existingTriple?.[3] ?? getCreatedAt(store, attr, triple);
340
340
  const enhancedTriple = [eid, aid, v, t];
341
341
  if (hasEA(attr)) {
342
342
  setInMap(store.eav, [eid, aid], new Map([[v, enhancedTriple]]));
@@ -351,7 +351,6 @@ export function addTriple(store, attrsStore, rawTriple) {
351
351
  }
352
352
  }
353
353
  function mergeTriple(store, attrsStore, rawTriple) {
354
- var _a;
355
354
  const triple = resolveLookupRefs(store, rawTriple);
356
355
  if (!triple) {
357
356
  return;
@@ -365,7 +364,7 @@ function mergeTriple(store, attrsStore, rawTriple) {
365
364
  const eavValuesMap = getInMap(store.eav, [eid, aid]);
366
365
  if (!eavValuesMap)
367
366
  return;
368
- const currentTriple = (_a = eavValuesMap.values().next()) === null || _a === void 0 ? void 0 : _a.value;
367
+ const currentTriple = eavValuesMap.values().next()?.value;
369
368
  if (!currentTriple)
370
369
  return;
371
370
  const currentValue = currentTriple[2];
@@ -380,7 +379,6 @@ function mergeTriple(store, attrsStore, rawTriple) {
380
379
  setInMap(store.aev, [aid, eid], new Map([[updatedValue, enhancedTriple]]));
381
380
  }
382
381
  function deleteEntity(store, attrsStore, args) {
383
- var _a, _b;
384
382
  const [lookup, etype] = args;
385
383
  const triple = resolveLookupRefs(store, [lookup]);
386
384
  if (!triple) {
@@ -394,7 +392,7 @@ function deleteEntity(store, attrsStore, args) {
394
392
  const attr = attrsStore.getAttr(a);
395
393
  // delete cascade refs
396
394
  if (attr && attr['on-delete-reverse'] === 'cascade') {
397
- allMapValues(eMap.get(a), 1).forEach(([e, a, v]) => { var _a; return deleteEntity(store, attrsStore, [v, (_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]]); });
395
+ allMapValues(eMap.get(a), 1).forEach(([e, a, v]) => deleteEntity(store, attrsStore, [v, attr['reverse-identity']?.[1]]));
398
396
  }
399
397
  if (
400
398
  // Fall back to deleting everything if we've rehydrated tx-steps from
@@ -403,7 +401,7 @@ function deleteEntity(store, attrsStore, args) {
403
401
  // If we don't know about the attr, let's just get rid of it
404
402
  !attr ||
405
403
  // Make sure it matches the etype
406
- ((_a = attr['forward-identity']) === null || _a === void 0 ? void 0 : _a[1]) === etype) {
404
+ attr['forward-identity']?.[1] === etype) {
407
405
  deleteInMap(store.aev, [a, id]);
408
406
  deleteInMap(store.eav, [id, a]);
409
407
  }
@@ -417,23 +415,22 @@ function deleteEntity(store, attrsStore, args) {
417
415
  const vaeTriples = store.vae.get(id) && allMapValues(store.vae.get(id), 2);
418
416
  if (vaeTriples) {
419
417
  vaeTriples.forEach((triple) => {
420
- var _a, _b, _c;
421
418
  const [e, a, v] = triple;
422
419
  const attr = attrsStore.getAttr(a);
423
- if (!etype || !attr || ((_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]) === etype) {
420
+ if (!etype || !attr || attr['reverse-identity']?.[1] === etype) {
424
421
  deleteInMap(store.eav, [e, a, v]);
425
422
  deleteInMap(store.aev, [a, e, v]);
426
423
  deleteInMap(store.vae, [v, a, e]);
427
424
  }
428
425
  if (attr &&
429
426
  attr['on-delete'] === 'cascade' &&
430
- ((_b = attr['reverse-identity']) === null || _b === void 0 ? void 0 : _b[1]) === etype) {
431
- deleteEntity(store, attrsStore, [e, (_c = attr['forward-identity']) === null || _c === void 0 ? void 0 : _c[1]]);
427
+ attr['reverse-identity']?.[1] === etype) {
428
+ deleteEntity(store, attrsStore, [e, attr['forward-identity']?.[1]]);
432
429
  }
433
430
  });
434
431
  }
435
432
  // Clear out vae index for `id` if we deleted all the reverse attributes
436
- if (((_b = store.vae.get(id)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
433
+ if (store.vae.get(id)?.size === 0) {
437
434
  deleteInMap(store.vae, [id]);
438
435
  }
439
436
  }
@@ -521,9 +518,8 @@ export function allMapValues(m, level, res = []) {
521
518
  return res;
522
519
  }
523
520
  function triplesByValue(store, m, v) {
524
- var _a;
525
521
  const res = [];
526
- if (v === null || v === void 0 ? void 0 : v.hasOwnProperty('$not')) {
522
+ if (v?.hasOwnProperty('$not')) {
527
523
  for (const candidate of m.keys()) {
528
524
  if (v.$not !== candidate) {
529
525
  res.push(m.get(candidate));
@@ -531,7 +527,7 @@ function triplesByValue(store, m, v) {
531
527
  }
532
528
  return res;
533
529
  }
534
- if (v === null || v === void 0 ? void 0 : v.hasOwnProperty('$isNull')) {
530
+ if (v?.hasOwnProperty('$isNull')) {
535
531
  const { attrId, isNull, reverse } = v.$isNull;
536
532
  if (reverse) {
537
533
  for (const candidate of m.keys()) {
@@ -545,7 +541,7 @@ function triplesByValue(store, m, v) {
545
541
  else {
546
542
  const aMap = store.aev.get(attrId);
547
543
  for (const candidate of m.keys()) {
548
- const isValNull = !aMap || ((_a = aMap.get(candidate)) === null || _a === void 0 ? void 0 : _a.get(null)) || !aMap.get(candidate);
544
+ const isValNull = !aMap || aMap.get(candidate)?.get(null) || !aMap.get(candidate);
549
545
  if (isNull ? isValNull : !isValNull) {
550
546
  res.push(m.get(candidate));
551
547
  }
@@ -553,7 +549,7 @@ function triplesByValue(store, m, v) {
553
549
  }
554
550
  return res;
555
551
  }
556
- if (v === null || v === void 0 ? void 0 : v.$comparator) {
552
+ if (v?.$comparator) {
557
553
  // TODO: A sorted index would be nice here
558
554
  return allMapValues(m, 1).filter(v.$op);
559
555
  }
@@ -582,7 +578,6 @@ function whichIdx(e, a, v) {
582
578
  return res;
583
579
  }
584
580
  export function getTriples(store, [e, a, v]) {
585
- var _a, _b;
586
581
  const idx = whichIdx(e, a, v);
587
582
  switch (idx) {
588
583
  case 'e': {
@@ -590,11 +585,11 @@ export function getTriples(store, [e, a, v]) {
590
585
  return allMapValues(eMap, 2);
591
586
  }
592
587
  case 'ea': {
593
- const aMap = (_a = store.eav.get(e)) === null || _a === void 0 ? void 0 : _a.get(a);
588
+ const aMap = store.eav.get(e)?.get(a);
594
589
  return allMapValues(aMap, 1);
595
590
  }
596
591
  case 'eav': {
597
- const aMap = (_b = store.eav.get(e)) === null || _b === void 0 ? void 0 : _b.get(a);
592
+ const aMap = store.eav.get(e)?.get(a);
598
593
  if (!aMap) {
599
594
  return [];
600
595
  }
@@ -641,13 +636,12 @@ export function getTriples(store, [e, a, v]) {
641
636
  }
642
637
  }
643
638
  export function getAsObject(store, attrs, e) {
644
- var _a;
645
639
  const obj = {};
646
640
  if (!attrs) {
647
641
  return obj;
648
642
  }
649
643
  for (const [label, attr] of attrs.entries()) {
650
- const aMap = (_a = store.eav.get(e)) === null || _a === void 0 ? void 0 : _a.get(attr.id);
644
+ const aMap = store.eav.get(e)?.get(attr.id);
651
645
  const triples = allMapValues(aMap, 1);
652
646
  for (const triple of triples) {
653
647
  obj[label] = triple[2];
@@ -656,23 +650,20 @@ export function getAsObject(store, attrs, e) {
656
650
  return obj;
657
651
  }
658
652
  export function getAttrByFwdIdentName(attrsStore, inputEtype, inputLabel) {
659
- var _a;
660
- return (_a = attrsStore.forwardIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
653
+ return attrsStore.forwardIdents.get(inputEtype)?.get(inputLabel);
661
654
  }
662
655
  export function getAttrByReverseIdentName(attrsStore, inputEtype, inputLabel) {
663
- var _a;
664
- return (_a = attrsStore.revIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
656
+ return attrsStore.revIdents.get(inputEtype)?.get(inputLabel);
665
657
  }
666
658
  export function getBlobAttrs(attrsStore, etype) {
667
659
  return attrsStore.blobAttrs.get(etype);
668
660
  }
669
661
  export function getPrimaryKeyAttr(attrsStore, etype) {
670
- var _a;
671
662
  const fromPrimary = attrsStore.primaryKeys.get(etype);
672
663
  if (fromPrimary) {
673
664
  return fromPrimary;
674
665
  }
675
- return (_a = attrsStore.forwardIdents.get(etype)) === null || _a === void 0 ? void 0 : _a.get('id');
666
+ return attrsStore.forwardIdents.get(etype)?.get('id');
676
667
  }
677
668
  function findTriple(store, attrsStore, rawTriple) {
678
669
  const triple = resolveLookupRefs(store, rawTriple);
@@ -695,7 +686,7 @@ export function transact(store, attrsStore, txSteps) {
695
686
  if (action !== 'add-triple' && action !== 'deep-merge-triple') {
696
687
  return true;
697
688
  }
698
- const mode = opts === null || opts === void 0 ? void 0 : opts.mode;
689
+ const mode = opts?.mode;
699
690
  if (mode !== 'create' && mode !== 'update') {
700
691
  return true;
701
692
  }
@@ -705,7 +696,7 @@ export function transact(store, attrsStore, txSteps) {
705
696
  const idAttr = getPrimaryKeyAttr(attrsStore, attr['forward-identity'][1]);
706
697
  exists = !!findTriple(store, attrsStore, [
707
698
  eid,
708
- idAttr === null || idAttr === void 0 ? void 0 : idAttr.id,
699
+ idAttr?.id,
709
700
  eid,
710
701
  ]);
711
702
  }