@instantdb/core 0.22.96-experimental.drewh-ts-target.20761590091.1 → 0.22.97-experimental.bump-next-cia.20761479934.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.
- package/dist/commonjs/Connection.js +51 -50
- package/dist/commonjs/Connection.js.map +1 -1
- package/dist/commonjs/InMemoryStorage.js +32 -13
- package/dist/commonjs/InMemoryStorage.js.map +1 -1
- package/dist/commonjs/IndexedDBStorage.js +217 -193
- package/dist/commonjs/IndexedDBStorage.js.map +1 -1
- package/dist/commonjs/InstantError.js +0 -1
- package/dist/commonjs/InstantError.js.map +1 -1
- package/dist/commonjs/Reactor.js +610 -566
- package/dist/commonjs/Reactor.js.map +1 -1
- package/dist/commonjs/StorageAPI.js +70 -51
- package/dist/commonjs/StorageAPI.js.map +1 -1
- package/dist/commonjs/SyncTable.js +81 -68
- package/dist/commonjs/SyncTable.js.map +1 -1
- package/dist/commonjs/WindowNetworkListener.js +13 -2
- package/dist/commonjs/WindowNetworkListener.js.map +1 -1
- package/dist/commonjs/__types__/fieldsTypeTest.js +16 -8
- package/dist/commonjs/__types__/fieldsTypeTest.js.map +1 -1
- package/dist/commonjs/__types__/useDatesTypeTest.js +6 -3
- package/dist/commonjs/__types__/useDatesTypeTest.js.map +1 -1
- package/dist/commonjs/authAPI.js +79 -62
- package/dist/commonjs/authAPI.js.map +1 -1
- package/dist/commonjs/createRouteHandler.js +15 -5
- package/dist/commonjs/createRouteHandler.js.map +1 -1
- package/dist/commonjs/datalog.js +1 -1
- package/dist/commonjs/datalog.js.map +1 -1
- package/dist/commonjs/devtool.js +8 -26
- package/dist/commonjs/devtool.js.map +1 -1
- package/dist/commonjs/framework.d.ts.map +1 -1
- package/dist/commonjs/framework.js +152 -142
- package/dist/commonjs/framework.js.map +1 -1
- package/dist/commonjs/index.js +190 -204
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/instaml.js +30 -44
- package/dist/commonjs/instaml.js.map +1 -1
- package/dist/commonjs/instaql.js +33 -25
- package/dist/commonjs/instaql.js.map +1 -1
- package/dist/commonjs/parseSchemaFromJSON.js +7 -6
- package/dist/commonjs/parseSchemaFromJSON.js.map +1 -1
- package/dist/commonjs/presence.js +8 -7
- package/dist/commonjs/presence.js.map +1 -1
- package/dist/commonjs/queryValidation.js +2 -1
- package/dist/commonjs/queryValidation.js.map +1 -1
- package/dist/commonjs/schema.js +6 -8
- package/dist/commonjs/schema.js.map +1 -1
- package/dist/commonjs/schemaTypes.js +3 -22
- package/dist/commonjs/schemaTypes.js.map +1 -1
- package/dist/commonjs/store.js +38 -29
- package/dist/commonjs/store.js.map +1 -1
- package/dist/commonjs/transactionValidation.js +2 -1
- package/dist/commonjs/transactionValidation.js.map +1 -1
- package/dist/commonjs/utils/Deferred.js +0 -3
- package/dist/commonjs/utils/Deferred.js.map +1 -1
- package/dist/commonjs/utils/PersistedObject.js +233 -216
- package/dist/commonjs/utils/PersistedObject.js.map +1 -1
- package/dist/commonjs/utils/fetch.js +19 -9
- package/dist/commonjs/utils/fetch.js.map +1 -1
- package/dist/commonjs/utils/linkIndex.js +4 -2
- package/dist/commonjs/utils/linkIndex.js.map +1 -1
- package/dist/commonjs/utils/object.js +1 -1
- package/dist/commonjs/utils/object.js.map +1 -1
- package/dist/esm/Connection.js +51 -50
- package/dist/esm/Connection.js.map +1 -1
- package/dist/esm/InMemoryStorage.js +32 -13
- package/dist/esm/InMemoryStorage.js.map +1 -1
- package/dist/esm/IndexedDBStorage.js +217 -193
- package/dist/esm/IndexedDBStorage.js.map +1 -1
- package/dist/esm/InstantError.js +0 -1
- package/dist/esm/InstantError.js.map +1 -1
- package/dist/esm/Reactor.js +610 -566
- package/dist/esm/Reactor.js.map +1 -1
- package/dist/esm/StorageAPI.js +70 -51
- package/dist/esm/StorageAPI.js.map +1 -1
- package/dist/esm/SyncTable.js +81 -68
- package/dist/esm/SyncTable.js.map +1 -1
- package/dist/esm/WindowNetworkListener.js +13 -2
- package/dist/esm/WindowNetworkListener.js.map +1 -1
- package/dist/esm/__types__/fieldsTypeTest.js +16 -8
- package/dist/esm/__types__/fieldsTypeTest.js.map +1 -1
- package/dist/esm/__types__/useDatesTypeTest.js +6 -3
- package/dist/esm/__types__/useDatesTypeTest.js.map +1 -1
- package/dist/esm/authAPI.js +79 -62
- package/dist/esm/authAPI.js.map +1 -1
- package/dist/esm/createRouteHandler.js +15 -5
- package/dist/esm/createRouteHandler.js.map +1 -1
- package/dist/esm/datalog.js +1 -1
- package/dist/esm/datalog.js.map +1 -1
- package/dist/esm/devtool.js +8 -26
- package/dist/esm/devtool.js.map +1 -1
- package/dist/esm/framework.d.ts.map +1 -1
- package/dist/esm/framework.js +152 -142
- package/dist/esm/framework.js.map +1 -1
- package/dist/esm/index.js +190 -204
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/instaml.js +30 -44
- package/dist/esm/instaml.js.map +1 -1
- package/dist/esm/instaql.js +33 -25
- package/dist/esm/instaql.js.map +1 -1
- package/dist/esm/parseSchemaFromJSON.js +7 -6
- package/dist/esm/parseSchemaFromJSON.js.map +1 -1
- package/dist/esm/presence.js +8 -7
- package/dist/esm/presence.js.map +1 -1
- package/dist/esm/queryValidation.js +2 -1
- package/dist/esm/queryValidation.js.map +1 -1
- package/dist/esm/schema.js +6 -8
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/schemaTypes.js +3 -22
- package/dist/esm/schemaTypes.js.map +1 -1
- package/dist/esm/store.js +38 -29
- package/dist/esm/store.js.map +1 -1
- package/dist/esm/transactionValidation.js +2 -1
- package/dist/esm/transactionValidation.js.map +1 -1
- package/dist/esm/utils/Deferred.js +0 -3
- package/dist/esm/utils/Deferred.js.map +1 -1
- package/dist/esm/utils/PersistedObject.js +233 -216
- package/dist/esm/utils/PersistedObject.js.map +1 -1
- package/dist/esm/utils/fetch.js +19 -9
- package/dist/esm/utils/fetch.js.map +1 -1
- package/dist/esm/utils/linkIndex.js +4 -2
- package/dist/esm/utils/linkIndex.js.map +1 -1
- package/dist/esm/utils/object.js +1 -1
- package/dist/esm/utils/object.js.map +1 -1
- package/dist/standalone/index.js +2367 -2610
- package/dist/standalone/index.umd.cjs +3 -3
- package/package.json +2 -2
- package/src/framework.ts +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queryValidation.js","sourceRoot":"","sources":["../../src/queryValidation.ts"],"names":[],"mappings":";;;AAAA,qDAI0B;AAC1B,+BAAgD;AAEhD,MAAa,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;AAND,oDAMC;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,EACd,YAA+B,EAC/B,YAAqB,KAAK,EACjB,EAAE;IACX,IAAI,SAAS;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAEvD,QAAQ,YAAY,EAAE,CAAC;QACrB,KAAK,QAAQ;YACX,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC;QACnC,KAAK,QAAQ;YACX,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC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,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;AAxDW,QAAA,aAAa,iBAwDxB","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,qDAI0B;AAC1B,+BAAgD;AAEhD,MAAa,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;AAND,oDAMC;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,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C;IAE9C,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,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;AAxDW,QAAA,aAAa,iBAwDxB","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"]}
|
package/dist/commonjs/schema.js
CHANGED
|
@@ -66,10 +66,11 @@ function any() {
|
|
|
66
66
|
// ==========
|
|
67
67
|
// internal
|
|
68
68
|
function enrichEntitiesWithLinks(entities, links) {
|
|
69
|
+
var _a, _b, _c, _d;
|
|
69
70
|
const linksIndex = { fwd: {}, rev: {} };
|
|
70
71
|
for (const linkDef of Object.values(links)) {
|
|
71
|
-
linksIndex.fwd[linkDef.forward.on]
|
|
72
|
-
linksIndex.rev[linkDef.reverse.on]
|
|
72
|
+
(_a = linksIndex.fwd)[_b = linkDef.forward.on] || (_a[_b] = {});
|
|
73
|
+
(_c = linksIndex.rev)[_d = linkDef.reverse.on] || (_c[_d] = {});
|
|
73
74
|
linksIndex.fwd[linkDef.forward.on][linkDef.forward.label] = {
|
|
74
75
|
entityName: linkDef.reverse.on,
|
|
75
76
|
cardinality: linkDef.forward.has,
|
|
@@ -81,10 +82,7 @@ function enrichEntitiesWithLinks(entities, links) {
|
|
|
81
82
|
}
|
|
82
83
|
const enrichedEntities = Object.fromEntries(Object.entries(entities).map(([name, def]) => [
|
|
83
84
|
name,
|
|
84
|
-
new schemaTypes_ts_1.EntityDef(def.attrs, {
|
|
85
|
-
...linksIndex.fwd[name],
|
|
86
|
-
...linksIndex.rev[name],
|
|
87
|
-
}),
|
|
85
|
+
new schemaTypes_ts_1.EntityDef(def.attrs, Object.assign(Object.assign({}, linksIndex.fwd[name]), linksIndex.rev[name])),
|
|
88
86
|
]));
|
|
89
87
|
return enrichedEntities;
|
|
90
88
|
}
|
|
@@ -106,8 +104,8 @@ function enrichEntitiesWithLinks(entities, links) {
|
|
|
106
104
|
* });
|
|
107
105
|
*/
|
|
108
106
|
function schema({ entities, links, rooms, }) {
|
|
109
|
-
const linksDef = (links
|
|
110
|
-
const roomsDef = (rooms
|
|
107
|
+
const linksDef = (links !== null && links !== void 0 ? links : {});
|
|
108
|
+
const roomsDef = (rooms !== null && rooms !== void 0 ? rooms : {});
|
|
111
109
|
return new schemaTypes_ts_1.InstantSchemaDef(enrichEntitiesWithLinks(entities, linksDef),
|
|
112
110
|
// (XXX): LinksDef<any> stems from TypeScript's inability to reconcile the
|
|
113
111
|
// type EntitiesWithLinks<EntitiesWithoutLinks, Links> with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/schema.ts"],"names":[],"mappings":";;;AAAA,q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KAAK,cAAL,KAAK,GAAI,EAAE,CAAU,CAAC;IACxC,OAAO,IAAI,iCAAgB,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;AAEY,QAAA,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"]}
|
|
@@ -2,16 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InstantUnknownSchemaDef = exports.InstantGraph = exports.InstantSchemaDef = exports.EntityDef = exports.LinkAttrDef = exports.DataAttrDef = void 0;
|
|
4
4
|
class DataAttrDef {
|
|
5
|
-
valueType;
|
|
6
|
-
required;
|
|
7
|
-
isIndexed;
|
|
8
|
-
config;
|
|
9
|
-
metadata = {};
|
|
10
5
|
constructor(valueType, required, isIndexed, config = { indexed: false, unique: false }) {
|
|
11
6
|
this.valueType = valueType;
|
|
12
7
|
this.required = required;
|
|
13
8
|
this.isIndexed = isIndexed;
|
|
14
9
|
this.config = config;
|
|
10
|
+
this.metadata = {};
|
|
15
11
|
}
|
|
16
12
|
/**
|
|
17
13
|
* @deprecated Only use this temporarily for attributes that you want
|
|
@@ -25,22 +21,14 @@ class DataAttrDef {
|
|
|
25
21
|
return new DataAttrDef(this.valueType, false, this.isIndexed, this.config);
|
|
26
22
|
}
|
|
27
23
|
unique() {
|
|
28
|
-
return new DataAttrDef(this.valueType, this.required, this.isIndexed, {
|
|
29
|
-
...this.config,
|
|
30
|
-
unique: true,
|
|
31
|
-
});
|
|
24
|
+
return new DataAttrDef(this.valueType, this.required, this.isIndexed, Object.assign(Object.assign({}, this.config), { unique: true }));
|
|
32
25
|
}
|
|
33
26
|
indexed() {
|
|
34
|
-
return new DataAttrDef(this.valueType, this.required, true, {
|
|
35
|
-
...this.config,
|
|
36
|
-
indexed: true,
|
|
37
|
-
});
|
|
27
|
+
return new DataAttrDef(this.valueType, this.required, true, Object.assign(Object.assign({}, this.config), { indexed: true }));
|
|
38
28
|
}
|
|
39
29
|
}
|
|
40
30
|
exports.DataAttrDef = DataAttrDef;
|
|
41
31
|
class LinkAttrDef {
|
|
42
|
-
cardinality;
|
|
43
|
-
entityName;
|
|
44
32
|
constructor(cardinality, entityName) {
|
|
45
33
|
this.cardinality = cardinality;
|
|
46
34
|
this.entityName = entityName;
|
|
@@ -48,8 +36,6 @@ class LinkAttrDef {
|
|
|
48
36
|
}
|
|
49
37
|
exports.LinkAttrDef = LinkAttrDef;
|
|
50
38
|
class EntityDef {
|
|
51
|
-
attrs;
|
|
52
|
-
links;
|
|
53
39
|
constructor(attrs, links) {
|
|
54
40
|
this.attrs = attrs;
|
|
55
41
|
this.links = links;
|
|
@@ -60,9 +46,6 @@ class EntityDef {
|
|
|
60
46
|
}
|
|
61
47
|
exports.EntityDef = EntityDef;
|
|
62
48
|
class InstantSchemaDef {
|
|
63
|
-
entities;
|
|
64
|
-
links;
|
|
65
|
-
rooms;
|
|
66
49
|
constructor(entities, links, rooms) {
|
|
67
50
|
this.entities = entities;
|
|
68
51
|
this.links = links;
|
|
@@ -99,8 +82,6 @@ exports.InstantSchemaDef = InstantSchemaDef;
|
|
|
99
82
|
* @see https://instantdb.com/docs/modeling-data
|
|
100
83
|
*/
|
|
101
84
|
class InstantGraph {
|
|
102
|
-
entities;
|
|
103
|
-
links;
|
|
104
85
|
constructor(entities, links) {
|
|
105
86
|
this.entities = entities;
|
|
106
87
|
this.links = links;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaTypes.js","sourceRoot":"","sources":["../../src/schemaTypes.ts"],"names":[],"mappings":";;;AAGA,MAAa,WAAW;IAQb;IACA;IACA;IAEA;IAPF,QAAQ,GAA4B,EAAE,CAAC;IAE9C,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;IACpC,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,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,SAAS,EACd;YACE,GAAG,IAAI,CAAC,MAAM;YACd,MAAM,EAAE,IAAI;SACb,CACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,IAAI,WAAW,CACpB,IAAI,CAAC,SAAS,EACd,IAAI,CAAC,QAAQ,EACb,IAAI,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aShape } 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":[],"mappings":";;;AAGA,MAAa,WAAW;IAOtB,YACS,SAAqB,EACrB,QAAoB,EACpB,SAAoB,EAEpB,SAIH,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;QAR9B,cAAS,GAAT,SAAS,CA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AAkB,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;AAvCD,4CAuCC;AAED;;;;;GAKG;AACH,MAAa,YAAY;IAMvB,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;AAjBD,oCAiBC;AAqGD,MAAa,uBAAwB,SAAQ,gBAI5C;CAAG;AAJJ,0DAII","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/commonjs/store.js
CHANGED
|
@@ -23,13 +23,11 @@ const mutative_1 = require("mutative");
|
|
|
23
23
|
const object_js_1 = require("./utils/object.js");
|
|
24
24
|
const dates_ts_1 = require("./utils/dates.js");
|
|
25
25
|
class AttrsStoreClass {
|
|
26
|
-
attrs;
|
|
27
|
-
linkIndex;
|
|
28
|
-
_blobAttrs = null;
|
|
29
|
-
_primaryKeys = null;
|
|
30
|
-
_forwardIdents = null;
|
|
31
|
-
_revIdents = null;
|
|
32
26
|
constructor(attrs, linkIndex) {
|
|
27
|
+
this._blobAttrs = null;
|
|
28
|
+
this._primaryKeys = null;
|
|
29
|
+
this._forwardIdents = null;
|
|
30
|
+
this._revIdents = null;
|
|
33
31
|
this.attrs = attrs;
|
|
34
32
|
this.linkIndex = linkIndex;
|
|
35
33
|
}
|
|
@@ -51,7 +49,7 @@ class AttrsStoreClass {
|
|
|
51
49
|
const attr = this.attrs[partialAttr.id];
|
|
52
50
|
if (!attr)
|
|
53
51
|
return;
|
|
54
|
-
this.attrs[partialAttr.id] = {
|
|
52
|
+
this.attrs[partialAttr.id] = Object.assign(Object.assign({}, attr), partialAttr);
|
|
55
53
|
this.resetAttrIndexes();
|
|
56
54
|
}
|
|
57
55
|
getAttr(id) {
|
|
@@ -243,6 +241,7 @@ function createStore(attrsStore, triples, enableCardinalityInference, useDateObj
|
|
|
243
241
|
// then we drop the triple and have to wait for the server response
|
|
244
242
|
// to see the optimistic updates.
|
|
245
243
|
function resolveLookupRefs(store, triple) {
|
|
244
|
+
var _a, _b;
|
|
246
245
|
let eid;
|
|
247
246
|
// Check if `e` is a lookup ref
|
|
248
247
|
if (Array.isArray(triple[0])) {
|
|
@@ -255,7 +254,7 @@ function resolveLookupRefs(store, triple) {
|
|
|
255
254
|
}
|
|
256
255
|
// This would be a lot more efficient with a ave index
|
|
257
256
|
const triples = allMapValues(eMaps, 2);
|
|
258
|
-
eid = triples.find((x) => x[2] === v)
|
|
257
|
+
eid = (_a = triples.find((x) => x[2] === v)) === null || _a === void 0 ? void 0 : _a[0];
|
|
259
258
|
}
|
|
260
259
|
else {
|
|
261
260
|
eid = triple[0];
|
|
@@ -278,7 +277,7 @@ function resolveLookupRefs(store, triple) {
|
|
|
278
277
|
return null;
|
|
279
278
|
}
|
|
280
279
|
const triples = allMapValues(eMaps, 2);
|
|
281
|
-
const value = triples.find((x) => x[2] === v)
|
|
280
|
+
const value = (_b = triples.find((x) => x[2] === v)) === null || _b === void 0 ? void 0 : _b[0];
|
|
282
281
|
if (!value) {
|
|
283
282
|
return null;
|
|
284
283
|
}
|
|
@@ -338,6 +337,7 @@ function getCreatedAt(store, attr, triple) {
|
|
|
338
337
|
return createdAt || Date.now() * 10 + _seed++;
|
|
339
338
|
}
|
|
340
339
|
function addTriple(store, attrsStore, rawTriple) {
|
|
340
|
+
var _a;
|
|
341
341
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
342
342
|
if (!triple) {
|
|
343
343
|
return;
|
|
@@ -358,7 +358,7 @@ function addTriple(store, attrsStore, rawTriple) {
|
|
|
358
358
|
// Reuse the created_at for a triple if it's already in the store.
|
|
359
359
|
// Prevents updates from temporarily pushing an entity to the top
|
|
360
360
|
// while waiting for the server response.
|
|
361
|
-
const t = existingTriple
|
|
361
|
+
const t = (_a = existingTriple === null || existingTriple === void 0 ? void 0 : existingTriple[3]) !== null && _a !== void 0 ? _a : getCreatedAt(store, attr, triple);
|
|
362
362
|
const enhancedTriple = [eid, aid, v, t];
|
|
363
363
|
if (hasEA(attr)) {
|
|
364
364
|
setInMap(store.eav, [eid, aid], new Map([[v, enhancedTriple]]));
|
|
@@ -373,6 +373,7 @@ function addTriple(store, attrsStore, rawTriple) {
|
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
function mergeTriple(store, attrsStore, rawTriple) {
|
|
376
|
+
var _a;
|
|
376
377
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
377
378
|
if (!triple) {
|
|
378
379
|
return;
|
|
@@ -386,7 +387,7 @@ function mergeTriple(store, attrsStore, rawTriple) {
|
|
|
386
387
|
const eavValuesMap = getInMap(store.eav, [eid, aid]);
|
|
387
388
|
if (!eavValuesMap)
|
|
388
389
|
return;
|
|
389
|
-
const currentTriple = eavValuesMap.values().next()
|
|
390
|
+
const currentTriple = (_a = eavValuesMap.values().next()) === null || _a === void 0 ? void 0 : _a.value;
|
|
390
391
|
if (!currentTriple)
|
|
391
392
|
return;
|
|
392
393
|
const currentValue = currentTriple[2];
|
|
@@ -401,6 +402,7 @@ function mergeTriple(store, attrsStore, rawTriple) {
|
|
|
401
402
|
setInMap(store.aev, [aid, eid], new Map([[updatedValue, enhancedTriple]]));
|
|
402
403
|
}
|
|
403
404
|
function deleteEntity(store, attrsStore, args) {
|
|
405
|
+
var _a, _b;
|
|
404
406
|
const [lookup, etype] = args;
|
|
405
407
|
const triple = resolveLookupRefs(store, [lookup]);
|
|
406
408
|
if (!triple) {
|
|
@@ -414,7 +416,7 @@ function deleteEntity(store, attrsStore, args) {
|
|
|
414
416
|
const attr = attrsStore.getAttr(a);
|
|
415
417
|
// delete cascade refs
|
|
416
418
|
if (attr && attr['on-delete-reverse'] === 'cascade') {
|
|
417
|
-
allMapValues(eMap.get(a), 1).forEach(([e, a, v]) => deleteEntity(store, attrsStore, [v, attr['reverse-identity']
|
|
419
|
+
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]]); });
|
|
418
420
|
}
|
|
419
421
|
if (
|
|
420
422
|
// Fall back to deleting everything if we've rehydrated tx-steps from
|
|
@@ -423,7 +425,7 @@ function deleteEntity(store, attrsStore, args) {
|
|
|
423
425
|
// If we don't know about the attr, let's just get rid of it
|
|
424
426
|
!attr ||
|
|
425
427
|
// Make sure it matches the etype
|
|
426
|
-
attr['forward-identity']
|
|
428
|
+
((_a = attr['forward-identity']) === null || _a === void 0 ? void 0 : _a[1]) === etype) {
|
|
427
429
|
deleteInMap(store.aev, [a, id]);
|
|
428
430
|
deleteInMap(store.eav, [id, a]);
|
|
429
431
|
}
|
|
@@ -437,22 +439,23 @@ function deleteEntity(store, attrsStore, args) {
|
|
|
437
439
|
const vaeTriples = store.vae.get(id) && allMapValues(store.vae.get(id), 2);
|
|
438
440
|
if (vaeTriples) {
|
|
439
441
|
vaeTriples.forEach((triple) => {
|
|
442
|
+
var _a, _b, _c;
|
|
440
443
|
const [e, a, v] = triple;
|
|
441
444
|
const attr = attrsStore.getAttr(a);
|
|
442
|
-
if (!etype || !attr || attr['reverse-identity']
|
|
445
|
+
if (!etype || !attr || ((_a = attr['reverse-identity']) === null || _a === void 0 ? void 0 : _a[1]) === etype) {
|
|
443
446
|
deleteInMap(store.eav, [e, a, v]);
|
|
444
447
|
deleteInMap(store.aev, [a, e, v]);
|
|
445
448
|
deleteInMap(store.vae, [v, a, e]);
|
|
446
449
|
}
|
|
447
450
|
if (attr &&
|
|
448
451
|
attr['on-delete'] === 'cascade' &&
|
|
449
|
-
attr['reverse-identity']
|
|
450
|
-
deleteEntity(store, attrsStore, [e, attr['forward-identity']
|
|
452
|
+
((_b = attr['reverse-identity']) === null || _b === void 0 ? void 0 : _b[1]) === etype) {
|
|
453
|
+
deleteEntity(store, attrsStore, [e, (_c = attr['forward-identity']) === null || _c === void 0 ? void 0 : _c[1]]);
|
|
451
454
|
}
|
|
452
455
|
});
|
|
453
456
|
}
|
|
454
457
|
// Clear out vae index for `id` if we deleted all the reverse attributes
|
|
455
|
-
if (store.vae.get(id)
|
|
458
|
+
if (((_b = store.vae.get(id)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
|
|
456
459
|
deleteInMap(store.vae, [id]);
|
|
457
460
|
}
|
|
458
461
|
}
|
|
@@ -540,8 +543,9 @@ function allMapValues(m, level, res = []) {
|
|
|
540
543
|
return res;
|
|
541
544
|
}
|
|
542
545
|
function triplesByValue(store, m, v) {
|
|
546
|
+
var _a;
|
|
543
547
|
const res = [];
|
|
544
|
-
if (v
|
|
548
|
+
if (v === null || v === void 0 ? void 0 : v.hasOwnProperty('$not')) {
|
|
545
549
|
for (const candidate of m.keys()) {
|
|
546
550
|
if (v.$not !== candidate) {
|
|
547
551
|
res.push(m.get(candidate));
|
|
@@ -549,7 +553,7 @@ function triplesByValue(store, m, v) {
|
|
|
549
553
|
}
|
|
550
554
|
return res;
|
|
551
555
|
}
|
|
552
|
-
if (v
|
|
556
|
+
if (v === null || v === void 0 ? void 0 : v.hasOwnProperty('$isNull')) {
|
|
553
557
|
const { attrId, isNull, reverse } = v.$isNull;
|
|
554
558
|
if (reverse) {
|
|
555
559
|
for (const candidate of m.keys()) {
|
|
@@ -563,7 +567,7 @@ function triplesByValue(store, m, v) {
|
|
|
563
567
|
else {
|
|
564
568
|
const aMap = store.aev.get(attrId);
|
|
565
569
|
for (const candidate of m.keys()) {
|
|
566
|
-
const isValNull = !aMap || aMap.get(candidate)
|
|
570
|
+
const isValNull = !aMap || ((_a = aMap.get(candidate)) === null || _a === void 0 ? void 0 : _a.get(null)) || !aMap.get(candidate);
|
|
567
571
|
if (isNull ? isValNull : !isValNull) {
|
|
568
572
|
res.push(m.get(candidate));
|
|
569
573
|
}
|
|
@@ -571,7 +575,7 @@ function triplesByValue(store, m, v) {
|
|
|
571
575
|
}
|
|
572
576
|
return res;
|
|
573
577
|
}
|
|
574
|
-
if (v
|
|
578
|
+
if (v === null || v === void 0 ? void 0 : v.$comparator) {
|
|
575
579
|
// TODO: A sorted index would be nice here
|
|
576
580
|
return allMapValues(m, 1).filter(v.$op);
|
|
577
581
|
}
|
|
@@ -600,6 +604,7 @@ function whichIdx(e, a, v) {
|
|
|
600
604
|
return res;
|
|
601
605
|
}
|
|
602
606
|
function getTriples(store, [e, a, v]) {
|
|
607
|
+
var _a, _b;
|
|
603
608
|
const idx = whichIdx(e, a, v);
|
|
604
609
|
switch (idx) {
|
|
605
610
|
case 'e': {
|
|
@@ -607,11 +612,11 @@ function getTriples(store, [e, a, v]) {
|
|
|
607
612
|
return allMapValues(eMap, 2);
|
|
608
613
|
}
|
|
609
614
|
case 'ea': {
|
|
610
|
-
const aMap = store.eav.get(e)
|
|
615
|
+
const aMap = (_a = store.eav.get(e)) === null || _a === void 0 ? void 0 : _a.get(a);
|
|
611
616
|
return allMapValues(aMap, 1);
|
|
612
617
|
}
|
|
613
618
|
case 'eav': {
|
|
614
|
-
const aMap = store.eav.get(e)
|
|
619
|
+
const aMap = (_b = store.eav.get(e)) === null || _b === void 0 ? void 0 : _b.get(a);
|
|
615
620
|
if (!aMap) {
|
|
616
621
|
return [];
|
|
617
622
|
}
|
|
@@ -658,12 +663,13 @@ function getTriples(store, [e, a, v]) {
|
|
|
658
663
|
}
|
|
659
664
|
}
|
|
660
665
|
function getAsObject(store, attrs, e) {
|
|
666
|
+
var _a;
|
|
661
667
|
const obj = {};
|
|
662
668
|
if (!attrs) {
|
|
663
669
|
return obj;
|
|
664
670
|
}
|
|
665
671
|
for (const [label, attr] of attrs.entries()) {
|
|
666
|
-
const aMap = store.eav.get(e)
|
|
672
|
+
const aMap = (_a = store.eav.get(e)) === null || _a === void 0 ? void 0 : _a.get(attr.id);
|
|
667
673
|
const triples = allMapValues(aMap, 1);
|
|
668
674
|
for (const triple of triples) {
|
|
669
675
|
obj[label] = triple[2];
|
|
@@ -672,20 +678,23 @@ function getAsObject(store, attrs, e) {
|
|
|
672
678
|
return obj;
|
|
673
679
|
}
|
|
674
680
|
function getAttrByFwdIdentName(attrsStore, inputEtype, inputLabel) {
|
|
675
|
-
|
|
681
|
+
var _a;
|
|
682
|
+
return (_a = attrsStore.forwardIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
|
|
676
683
|
}
|
|
677
684
|
function getAttrByReverseIdentName(attrsStore, inputEtype, inputLabel) {
|
|
678
|
-
|
|
685
|
+
var _a;
|
|
686
|
+
return (_a = attrsStore.revIdents.get(inputEtype)) === null || _a === void 0 ? void 0 : _a.get(inputLabel);
|
|
679
687
|
}
|
|
680
688
|
function getBlobAttrs(attrsStore, etype) {
|
|
681
689
|
return attrsStore.blobAttrs.get(etype);
|
|
682
690
|
}
|
|
683
691
|
function getPrimaryKeyAttr(attrsStore, etype) {
|
|
692
|
+
var _a;
|
|
684
693
|
const fromPrimary = attrsStore.primaryKeys.get(etype);
|
|
685
694
|
if (fromPrimary) {
|
|
686
695
|
return fromPrimary;
|
|
687
696
|
}
|
|
688
|
-
return attrsStore.forwardIdents.get(etype)
|
|
697
|
+
return (_a = attrsStore.forwardIdents.get(etype)) === null || _a === void 0 ? void 0 : _a.get('id');
|
|
689
698
|
}
|
|
690
699
|
function findTriple(store, attrsStore, rawTriple) {
|
|
691
700
|
const triple = resolveLookupRefs(store, rawTriple);
|
|
@@ -708,7 +717,7 @@ function transact(store, attrsStore, txSteps) {
|
|
|
708
717
|
if (action !== 'add-triple' && action !== 'deep-merge-triple') {
|
|
709
718
|
return true;
|
|
710
719
|
}
|
|
711
|
-
const mode = opts
|
|
720
|
+
const mode = opts === null || opts === void 0 ? void 0 : opts.mode;
|
|
712
721
|
if (mode !== 'create' && mode !== 'update') {
|
|
713
722
|
return true;
|
|
714
723
|
}
|
|
@@ -718,7 +727,7 @@ function transact(store, attrsStore, txSteps) {
|
|
|
718
727
|
const idAttr = getPrimaryKeyAttr(attrsStore, attr['forward-identity'][1]);
|
|
719
728
|
exists = !!findTriple(store, attrsStore, [
|
|
720
729
|
eid,
|
|
721
|
-
idAttr
|
|
730
|
+
idAttr === null || idAttr === void 0 ? void 0 : idAttr.id,
|
|
722
731
|
eid,
|
|
723
732
|
]);
|
|
724
733
|
}
|