@seedprotocol/sdk 0.3.9 → 0.3.11
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/bin.js +182 -111
- package/dist/bin.js.map +1 -1
- package/dist/main.js +3 -2
- package/dist/main.js.map +1 -1
- package/dist/node/db/node.app.db.config.ts +7 -26
- package/dist/scripts/bin.d.ts +4 -4
- package/dist/scripts/bin.d.ts.map +1 -1
- package/dist/seedData.json +23 -0
- package/dist/src/Item/BaseItem.js +3 -3
- package/dist/src/Item/BaseItem.js.map +1 -1
- package/dist/src/ItemProperty/BaseItemProperty.d.ts +4 -1
- package/dist/src/ItemProperty/BaseItemProperty.d.ts.map +1 -1
- package/dist/src/ItemProperty/BaseItemProperty.js +65 -21
- package/dist/src/ItemProperty/BaseItemProperty.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.js +27 -17
- package/dist/src/ItemProperty/service/actors/hydrateFromDb.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/initialize.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/initialize.js +25 -20
- package/dist/src/ItemProperty/service/actors/initialize.js.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.d.ts.map +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.js +1 -1
- package/dist/src/ItemProperty/service/actors/resolveRemoteStorage.js.map +1 -1
- package/dist/src/ItemProperty/service/propertyMachine.d.ts +11 -11
- package/dist/src/browser/Item/Item.js +0 -1
- package/dist/src/browser/Item/Item.js.map +1 -1
- package/dist/src/browser/ItemProperty/ItemProperty.d.ts.map +1 -1
- package/dist/src/browser/ItemProperty/ItemProperty.js +0 -1
- package/dist/src/browser/ItemProperty/ItemProperty.js.map +1 -1
- package/dist/src/browser/db/Db.d.ts.map +1 -1
- package/dist/src/browser/db/Db.js +0 -2
- package/dist/src/browser/db/Db.js.map +1 -1
- package/dist/src/browser/helpers/FileManager.d.ts +1 -1
- package/dist/src/browser/helpers/FileManager.d.ts.map +1 -1
- package/dist/src/browser/helpers/FileManager.js +4 -4
- package/dist/src/browser/helpers/FileManager.js.map +1 -1
- package/dist/src/browser/helpers/eas.d.ts +20 -0
- package/dist/src/browser/helpers/eas.d.ts.map +1 -0
- package/dist/src/browser/helpers/eas.js +89 -0
- package/dist/src/browser/helpers/eas.js.map +1 -0
- package/dist/src/browser/react/SeedImage.d.ts +11 -0
- package/dist/src/browser/react/SeedImage.d.ts.map +1 -0
- package/dist/src/browser/react/SeedImage.js +105 -0
- package/dist/src/browser/react/SeedImage.js.map +1 -0
- package/dist/src/browser/react/item.d.ts +8 -8
- package/dist/src/browser/react/item.d.ts.map +1 -1
- package/dist/src/browser/react/item.js +9 -53
- package/dist/src/browser/react/item.js.map +1 -1
- package/dist/src/browser/react/property.d.ts +3 -3
- package/dist/src/browser/react/property.d.ts.map +1 -1
- package/dist/src/browser/react/property.js.map +1 -1
- package/dist/src/browser/react/services.d.ts.map +1 -1
- package/dist/src/browser/react/services.js +5 -0
- package/dist/src/browser/react/services.js.map +1 -1
- package/dist/src/browser/workers/FileDownloader.d.ts.map +1 -1
- package/dist/src/browser/workers/FileDownloader.js +1 -0
- package/dist/src/browser/workers/FileDownloader.js.map +1 -1
- package/dist/src/browser/workers/ImageResizer.d.ts.map +1 -1
- package/dist/src/browser/workers/ImageResizer.js +1 -0
- package/dist/src/browser/workers/ImageResizer.js.map +1 -1
- package/dist/src/browser/workers/filesDownload.d.ts.map +1 -1
- package/dist/src/browser/workers/filesDownload.js +4 -0
- package/dist/src/browser/workers/filesDownload.js.map +1 -1
- package/dist/src/browser/workers/imageResize.d.ts.map +1 -1
- package/dist/src/browser/workers/imageResize.js +4 -1
- package/dist/src/browser/workers/imageResize.js.map +1 -1
- package/dist/src/client/BaseClientManager.d.ts.map +1 -1
- package/dist/src/client/ClientManager.d.ts +173 -20
- package/dist/src/client/ClientManager.d.ts.map +1 -1
- package/dist/src/client/ClientManager.js +8 -0
- package/dist/src/client/ClientManager.js.map +1 -1
- package/dist/src/client/actors/initialize.d.ts +2 -2
- package/dist/src/client/actors/initialize.d.ts.map +1 -1
- package/dist/src/client/actors/initialize.js +9 -0
- package/dist/src/client/actors/initialize.js.map +1 -1
- package/dist/src/client/actors/saveAppState.d.ts.map +1 -1
- package/dist/src/client/actors/saveAppState.js +3 -2
- package/dist/src/client/actors/saveAppState.js.map +1 -1
- package/dist/src/client/clientManagerMachine.d.ts +86 -10
- package/dist/src/client/clientManagerMachine.d.ts.map +1 -1
- package/dist/src/client/clientManagerMachine.js +3 -1
- package/dist/src/client/clientManagerMachine.js.map +1 -1
- package/dist/src/db/read/getModelSchemas.d.ts +1 -2
- package/dist/src/db/read/getModelSchemas.d.ts.map +1 -1
- package/dist/src/db/read/getModelSchemas.js +1 -21
- package/dist/src/db/read/getModelSchemas.js.map +1 -1
- package/dist/src/db/read/getModels.d.ts +4 -1
- package/dist/src/db/read/getModels.d.ts.map +1 -1
- package/dist/src/db/read/getModels.js +16 -0
- package/dist/src/db/read/getModels.js.map +1 -0
- package/dist/src/db/read/getPublishPayload.d.ts.map +1 -1
- package/dist/src/db/read/getPublishPayload.js +52 -14
- package/dist/src/db/read/getPublishPayload.js.map +1 -1
- package/dist/src/db/read/getPublishUploads.d.ts.map +1 -1
- package/dist/src/db/read/getPublishUploads.js +34 -3
- package/dist/src/db/read/getPublishUploads.js.map +1 -1
- package/dist/src/events/item/syncDbWithEas.d.ts.map +1 -1
- package/dist/src/events/item/syncDbWithEas.js +9 -28
- package/dist/src/events/item/syncDbWithEas.js.map +1 -1
- package/dist/src/helpers/constants.d.ts +2 -2
- package/dist/src/helpers/constants.d.ts.map +1 -1
- package/dist/src/helpers/constants.js +14 -6
- package/dist/src/helpers/constants.js.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.d.ts +1 -0
- package/dist/src/helpers/getSegmentedItemProperties.d.ts.map +1 -1
- package/dist/src/helpers/getSegmentedItemProperties.js +6 -2
- package/dist/src/helpers/getSegmentedItemProperties.js.map +1 -1
- package/dist/src/helpers/index.d.ts +2 -1
- package/dist/src/helpers/index.d.ts.map +1 -1
- package/dist/src/helpers/index.js +4 -10
- package/dist/src/helpers/index.js.map +1 -1
- package/dist/src/helpers/scripts.d.ts +2 -0
- package/dist/src/helpers/scripts.d.ts.map +1 -0
- package/dist/src/helpers/scripts.js +14 -0
- package/dist/src/helpers/scripts.js.map +1 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/interfaces/IItemProperty.d.ts +7 -0
- package/dist/src/interfaces/IItemProperty.d.ts.map +1 -1
- package/dist/src/node/PathResolver.d.ts +39 -0
- package/dist/src/node/PathResolver.d.ts.map +1 -0
- package/dist/src/node/PathResolver.js +150 -0
- package/dist/src/node/PathResolver.js.map +1 -0
- package/dist/src/node/codegen/drizzle.d.ts.map +1 -1
- package/dist/src/node/codegen/drizzle.js +25 -4
- package/dist/src/node/codegen/drizzle.js.map +1 -1
- package/dist/src/node/constants.d.ts +0 -11
- package/dist/src/node/constants.d.ts.map +1 -1
- package/dist/src/node/constants.js +1 -32
- package/dist/src/node/constants.js.map +1 -1
- package/dist/src/node/db/node.app.db.config.d.ts.map +1 -1
- package/dist/src/schema/image/model.d.ts +8 -0
- package/dist/src/schema/image/model.d.ts.map +1 -0
- package/dist/src/schema/image/model.js +29 -0
- package/dist/src/schema/image/model.js.map +1 -0
- package/dist/src/schema/model/index.d.ts +8 -8
- package/dist/src/schema/property/index.d.ts +33 -45
- package/dist/src/schema/property/index.d.ts.map +1 -1
- package/dist/src/schema/property/index.js +0 -1
- package/dist/src/schema/property/index.js.map +1 -1
- package/dist/src/seedSchema/ConfigSchema.js +18 -0
- package/dist/src/seedSchema/ConfigSchema.js.map +1 -0
- package/dist/src/services/db/actors/migrate.js +1 -1
- package/dist/src/services/db/actors/migrate.js.map +1 -1
- package/dist/src/services/global/globalMachine.d.ts +90 -90
- package/dist/src/stores/eas.d.ts +12 -5
- package/dist/src/stores/eas.d.ts.map +1 -1
- package/dist/src/stores/eas.js +13 -8
- package/dist/src/stores/eas.js.map +1 -1
- package/dist/src/stores/modelClass.d.ts.map +1 -1
- package/dist/src/stores/modelClass.js.map +1 -1
- package/package.json +2 -1
- package/dist/src/Item/index.d.ts +0 -5
- package/dist/src/Item/index.d.ts.map +0 -1
- package/dist/src/Item/index.js +0 -4
- package/dist/src/Item/index.js.map +0 -1
- package/dist/src/ItemProperty/index.d.ts +0 -5
- package/dist/src/ItemProperty/index.d.ts.map +0 -1
- package/dist/src/ItemProperty/index.js +0 -4
- package/dist/src/ItemProperty/index.js.map +0 -1
- package/dist/src/ItemProperty/service/actors/index.d.ts +0 -4
- package/dist/src/ItemProperty/service/actors/index.d.ts.map +0 -1
- package/dist/src/browser/Item/index.d.ts +0 -2
- package/dist/src/browser/Item/index.d.ts.map +0 -1
- package/dist/src/browser/Item/index.js +0 -2
- package/dist/src/browser/Item/index.js.map +0 -1
- package/dist/src/browser/ItemProperty/index.d.ts +0 -2
- package/dist/src/browser/ItemProperty/index.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/helpers/index.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\nimport * as nanoIdDictionary from 'nanoid-dictionary'\nimport debug from 'debug'\nimport { GetCorrectId } from '@/types/helpers'\nimport { GetCorrectIdReturn } from '@/types/helpers'\nimport { BaseFileManager } from './FileManager/BaseFileManager'\nexport * from './ArweaveClient/BaseArweaveClient'\nexport * from './EasClient/BaseEasClient'\nexport * from './QueryClient/BaseQueryClient'\nexport * from './FileManager/BaseFileManager'\nconst logger = debug('seedSdk:shared:helpers')\n\n\nconst { alphanumeric } = nanoIdDictionary\n\nexport const generateId = (): string => {\n return customAlphabet(alphanumeric, 10)()\n}\n\nexport const toSnakeCase = (str: string) => {\n return str.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()\n}\n\nexport const identifyString = (str: string) => {\n try {\n JSON.parse(str)\n return 'json'\n } catch (e) {\n // Not JSON\n }\n\n if (!str) {\n return\n }\n\n if (str.trim().startsWith('<') && str.trim().endsWith('>')) {\n return 'html'\n }\n\n // Simple markdown checks (very naive)\n if (/^#{1,6}\\s|^-{3,}|\\*{3,}|^-{1,2}\\s|\\*\\s/.test(str)) {\n return 'markdown'\n }\n\n if (/^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {\n return 'base64'\n }\n\n // Default to plain text if unsure\n return 'text'\n}\n\nexport const getMimeType = (base64: string) => {\n if (!base64) {\n return null\n }\n const result = base64.match(/^data:([a-zA-Z0-9]+\\/[a-zA-Z0-9-.+]+).*,/)\n\n if (result && result.length > 1) {\n return result[1]\n } else {\n return null // MIME type could not be determined\n }\n}\n\nexport const getCorrectId: GetCorrectId = (localIdOrUid: string) => {\n const id: GetCorrectIdReturn = {\n localId: undefined,\n uid: undefined,\n }\n if (!localIdOrUid) {\n return id\n }\n if (localIdOrUid.length === 10) {\n id.localId = localIdOrUid\n }\n if (localIdOrUid.startsWith('0x') && localIdOrUid.length === 66) {\n id.uid = localIdOrUid\n }\n return id\n}\n\nexport const getDataTypeFromString = (\n data: string,\n): 'imageBase64' | 'base64' | 'url' | null => {\n const nonImageBase64Regex =\n /^(?!data:image\\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/\n\n if (nonImageBase64Regex.test(data)) {\n return 'base64'\n }\n\n // Regular expression for base64 (simple version, checking for base64 format)\n const imageBase64Regex = /^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/\n\n if (imageBase64Regex.test(data)) {\n return 'imageBase64'\n }\n\n // Regular expression for URL (simple version, checking for common URL format)\n const urlRegex =\n /^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$/\n\n if (urlRegex.test(data)) {\n return 'url'\n }\n\n return null\n}\n\nexport const convertTxIdToImage = async (\n txId: string,\n): Promise<string | undefined> => {\n const imageFilePath = `/files/images/${txId}`\n const fileExists = await BaseFileManager.pathExists(imageFilePath)\n if (!fileExists) {\n logger(`[ItemView] [updateImage] ${imageFilePath} does not exist`)\n return\n }\n const buffer = await BaseFileManager.readFileAsBuffer(imageFilePath)\n\n const uint = new Uint8Array(buffer)\n\n const imageBlob = new Blob([uint])\n\n return URL.createObjectURL(imageBlob)\n}\n\nexport const getExecutionTime = async (task, args) => {\n const start = Date.now()\n await task(...args)\n return Date.now() - start\n}\n\nexport const capitalizeFirstLetter = (string: string) =>\n string.charAt(0).toUpperCase() + string.slice(1)\n\nexport const parseEasRelationPropertyName = (easPropertyName: string) => {\n // Split the input string on the first underscore\n const [singularProperty, modelName, idSegment] = easPropertyName.split('_')\n\n // If there are any other parts, assume it is a list (e.g., has 'ids' or other suffix)\n const isList = idSegment === 'ids'\n\n // Create the final property name by pluralizing the singular part\n const propertyName = singularProperty.endsWith('s')\n ? singularProperty\n : singularProperty + 's'\n\n return {\n propertyName, // Plural form of the property name\n modelName, // Model name extracted from the second part\n isList, // True if the property is a list (e.g., 'ids' is present)\n }\n}\n\nexport const getContentHash = async (\n base64: string | null | undefined,\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/helpers/index.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\nimport * as sha3 from 'js-sha3'\nimport { Message } from 'js-sha3'\nimport * as nanoIdDictionary from 'nanoid-dictionary'\nimport debug from 'debug'\nimport { GetCorrectId } from '@/types/helpers'\nimport { GetCorrectIdReturn } from '@/types/helpers'\nimport { BaseFileManager } from './FileManager/BaseFileManager'\nexport * from './ArweaveClient/BaseArweaveClient'\nexport * from './EasClient/BaseEasClient'\nexport * from './QueryClient/BaseQueryClient'\nexport * from './FileManager/BaseFileManager'\nconst logger = debug('seedSdk:shared:helpers')\n\nconst { sha3_256, } = sha3\n\nconst { alphanumeric } = nanoIdDictionary\n\nexport const generateId = (): string => {\n return customAlphabet(alphanumeric, 10)()\n}\n\nexport const toSnakeCase = (str: string) => {\n return str.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase()\n}\n\nexport const identifyString = (str: string) => {\n try {\n JSON.parse(str)\n return 'json'\n } catch (e) {\n // Not JSON\n }\n\n if (!str) {\n return\n }\n\n if (str.trim().startsWith('<') && str.trim().endsWith('>')) {\n return 'html'\n }\n\n // Simple markdown checks (very naive)\n if (/^#{1,6}\\s|^-{3,}|\\*{3,}|^-{1,2}\\s|\\*\\s/.test(str)) {\n return 'markdown'\n }\n\n if (/^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/.test(str)) {\n return 'base64'\n }\n\n // Default to plain text if unsure\n return 'text'\n}\n\nexport const getMimeType = (base64: string) => {\n if (!base64) {\n return null\n }\n const result = base64.match(/^data:([a-zA-Z0-9]+\\/[a-zA-Z0-9-.+]+).*,/)\n\n if (result && result.length > 1) {\n return result[1]\n } else {\n return null // MIME type could not be determined\n }\n}\n\nexport const getCorrectId: GetCorrectId = (localIdOrUid: string) => {\n const id: GetCorrectIdReturn = {\n localId: undefined,\n uid: undefined,\n }\n if (!localIdOrUid) {\n return id\n }\n if (localIdOrUid.length === 10) {\n id.localId = localIdOrUid\n }\n if (localIdOrUid.startsWith('0x') && localIdOrUid.length === 66) {\n id.uid = localIdOrUid\n }\n return id\n}\n\nexport const getDataTypeFromString = (\n data: string,\n): 'imageBase64' | 'base64' | 'url' | null => {\n const nonImageBase64Regex =\n /^(?!data:image\\/(?:jpeg|png|gif|bmp|webp);base64,)[A-Za-z0-9+/=]+$/\n\n if (nonImageBase64Regex.test(data)) {\n return 'base64'\n }\n\n // Regular expression for base64 (simple version, checking for base64 format)\n const imageBase64Regex = /^data:image\\/[a-zA-Z]+;base64,[A-Za-z0-9+/]+={0,2}$/\n\n if (imageBase64Regex.test(data)) {\n return 'imageBase64'\n }\n\n // Regular expression for URL (simple version, checking for common URL format)\n const urlRegex =\n /^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$/\n\n if (urlRegex.test(data)) {\n return 'url'\n }\n\n return null\n}\n\nexport const convertTxIdToImage = async (\n txId: string,\n): Promise<string | undefined> => {\n const imageFilePath = `/files/images/${txId}`\n const fileExists = await BaseFileManager.pathExists(imageFilePath)\n if (!fileExists) {\n logger(`[ItemView] [updateImage] ${imageFilePath} does not exist`)\n return\n }\n const buffer = await BaseFileManager.readFileAsBuffer(imageFilePath)\n\n const uint = new Uint8Array(buffer)\n\n const imageBlob = new Blob([uint])\n\n return URL.createObjectURL(imageBlob)\n}\n\nexport const getExecutionTime = async (task, args) => {\n const start = Date.now()\n await task(...args)\n return Date.now() - start\n}\n\nexport const capitalizeFirstLetter = (string: string) =>\n string.charAt(0).toUpperCase() + string.slice(1)\n\nexport const parseEasRelationPropertyName = (easPropertyName: string) => {\n // Split the input string on the first underscore\n const [singularProperty, modelName, idSegment] = easPropertyName.split('_')\n\n // If there are any other parts, assume it is a list (e.g., has 'ids' or other suffix)\n const isList = idSegment === 'ids'\n\n // Create the final property name by pluralizing the singular part\n const propertyName = singularProperty.endsWith('s')\n ? singularProperty\n : singularProperty + 's'\n\n return {\n propertyName, // Plural form of the property name\n modelName, // Model name extracted from the second part\n isList, // True if the property is a list (e.g., 'ids' is present)\n }\n}\n\nexport const getContentHash = async (\n data: Message\n): Promise<string> => {\n return sha3_256(data)\n}\n\n// export const getContentHash = async (\n// base64: string | null | undefined,\n// uint: Uint8Array | undefined,\n// ): Promise<string> => {\n// let data\n\n// if (base64 && !uint) {\n// const encoder = new TextEncoder()\n// data = encoder.encode(base64)\n// }\n\n// if (uint) {\n// data = uint\n// }\n\n// // Hash the data with SHA-256\n// const hashBuffer = await crypto.subtle.digest('SHA-256', data as Uint8Array)\n\n// // Convert the ArrayBuffer to a hex string\n// const hashArray = Array.from(new Uint8Array(hashBuffer))\n// return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('')\n// }\n\nexport const isBinary = (arrayBuffer: ArrayBuffer): boolean => {\n const view = new Uint8Array(arrayBuffer);\n\n let nonTextCount = 0;\n const threshold = 0.2; // Adjust as needed (e.g., 20% non-text implies binary)\n\n for (let i = 0; i < view.length; i++) {\n const byte = view[i];\n\n // ASCII printable characters (32-126) and common whitespace (9, 10, 13)\n if (\n (byte >= 32 && byte <= 126) || // Printable ASCII\n byte === 9 || byte === 10 || byte === 13 // Tab, LF, CR\n ) {\n continue;\n }\n\n nonTextCount++;\n if (nonTextCount / view.length > threshold) {\n return true; // More than threshold are non-text bytes\n }\n }\n\n return false; // Fewer than threshold are non-text bytes\n}\n"],"names":[],"mappings":";;;;;;;;AAYA,MAAM,MAAM,GAAG,KAAK,CAAC,wBAAwB,CAAC;AAE9C,MAAM,EAAE,QAAQ,GAAG,GAAG,IAAI;AAE1B,MAAM,EAAE,YAAY,EAAE,GAAG,gBAAgB;AAElC,MAAM,UAAU,GAAG,MAAa;AACrC,IAAA,OAAO,cAAc,CAAC,YAAY,EAAE,EAAE,CAAC,EAAE;AAC3C;AAEa,MAAA,WAAW,GAAG,CAAC,GAAW,KAAI;IACzC,OAAO,GAAG,CAAC,OAAO,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,WAAW,EAAE;AAC9D;AA+Ba,MAAA,WAAW,GAAG,CAAC,MAAc,KAAI;IAC5C,IAAI,CAAC,MAAM,EAAE;AACX,QAAA,OAAO,IAAI;;IAEb,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,0CAA0C,CAAC;IAEvE,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;AAC/B,QAAA,OAAO,MAAM,CAAC,CAAC,CAAC;;SACX;QACL,OAAO,IAA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GAAG,MAAM,eAAe,CAAC,gBAAgB,CAAC,aAAa,CAAC;AAEpE,IAAA,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC;IAEnC,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;AAElC,IAAA,OAAO,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC;AACvC;AAWa,MAAA,4BAA4B,GAAG,CAAC,eAAuB,KAAI;;AAEtE,IAAA,MAAM,CAAC,gBAAgB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC;;AAG3E,IAAA,MAAM,MAAM,GAAG,SAAS,KAAK,KAAK;;AAGlC,IAAA,MAAM,YAAY,GAAG,gBAAgB,CAAC,QAAQ,CAAC,GAAG;AAChD,UAAE;AACF,UAAE,gBAAgB,GAAG,GAAG;IAE1B,OAAO;AACL,QAAA,YAAY;AACZ,QAAA,SAAS;AACT,QAAA,MAAM;KACP;AACH;MAEa,cAAc,GAAG,OAC5B,IAAa,KACM;AACnB,IAAA,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../../../src/helpers/scripts.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,YAAa,MAAM,KAAG,OAO/C,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { execSync } from 'child_process';
|
|
2
|
+
|
|
3
|
+
const commandExists = (command) => {
|
|
4
|
+
try {
|
|
5
|
+
execSync(`which ${command}`, { stdio: 'ignore' });
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export { commandExists };
|
|
14
|
+
//# sourceMappingURL=scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripts.js","sources":["../../../../src/helpers/scripts.ts"],"sourcesContent":["import { execSync } from 'child_process'\n\nexport const commandExists = (command: string): boolean => {\n try {\n execSync(`which ${command}`, { stdio: 'ignore' })\n return true\n } catch {\n return false\n }\n}\n"],"names":[],"mappings":";;AAEa,MAAA,aAAa,GAAG,CAAC,OAAe,KAAa;AACxD,IAAA,IAAI;QACF,QAAQ,CAAC,CAAS,MAAA,EAAA,OAAO,CAAE,CAAA,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACjD,QAAA,OAAO,IAAI;;AACX,IAAA,MAAM;AACN,QAAA,OAAO,KAAK;;AAEhB;;;;"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import SeedImage from './browser/react/SeedImage';
|
|
1
2
|
export { Model, Property, Image, List, Text, Json, Relation, Boolean, Number, Date, } from './schema';
|
|
2
|
-
export { Item } from './Item';
|
|
3
|
-
export { ItemProperty } from './ItemProperty';
|
|
3
|
+
export { BaseItem as Item } from './Item/BaseItem';
|
|
4
|
+
export { BaseItemProperty as ItemProperty } from './ItemProperty/BaseItemProperty';
|
|
4
5
|
export { useItems, useItem, useItemProperties, useCreateItem, useItemProperty, useDeleteItem, useGlobalServiceStatus, usePublishItem, usePersistedSnapshots, useServices, useService, useModels, } from './browser/react';
|
|
6
|
+
export { SeedImage };
|
|
5
7
|
export { FileManager as FileManagerBrowser } from './browser/helpers/FileManager';
|
|
6
8
|
export { Db as DbBrowser } from './browser/db/Db';
|
|
7
9
|
export { models, versions, seeds, metadata, } from './seedSchema';
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,2BAA2B,CAAA;AAGjD,OAAO,EACL,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,MAAM,EACN,IAAI,GACL,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAE,QAAQ,IAAI,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,gBAAgB,IAAI,YAAY,EAAE,MAAM,iCAAiC,CAAA;AAElF,OAAO,EACL,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,aAAa,EACb,eAAe,EACf,aAAa,EACb,sBAAsB,EACtB,cAAc,EACd,qBAAqB,EACrB,WAAW,EACX,UAAU,EACV,SAAS,GACV,MAAM,iBAAiB,CAAA;AAGxB,OAAO,EAAE,SAAS,EAAE,CAAA;AAEpB,OAAO,EAAC,WAAW,IAAI,kBAAkB,EAAC,MAAM,+BAA+B,CAAA;AAC/E,OAAO,EAAC,EAAE,IAAI,SAAS,EAAC,MAAM,iBAAiB,CAAA;AAE/C,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,GAAG,MAAM,cAAc,CAAA;AAEhE,OAAO,EAAC,SAAS,EAAE,QAAQ,EAAE,aAAa,GAAE,MAAM,qBAAqB,CAAA;AAEvE,OAAO,EAAE,YAAY,GAAG,MAAM,WAAW,CAAA;AAEzC,OAAO,EACL,YAAY,GACb,MAAM,YAAY,CAAA;AAInB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,YAAY,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAGhE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,cAAc,SAAS,CAAA"}
|
|
@@ -2,6 +2,7 @@ import { ActorRefFrom, Subscription } from 'xstate';
|
|
|
2
2
|
import { BehaviorSubject } from 'rxjs';
|
|
3
3
|
import { Static } from '@sinclair/typebox';
|
|
4
4
|
import { TProperty } from '@/schema';
|
|
5
|
+
import { BaseItemProperty } from '@/ItemProperty/BaseItemProperty';
|
|
5
6
|
export interface IItemProperty<PropertyType> {
|
|
6
7
|
readonly localId: string;
|
|
7
8
|
readonly uid: string;
|
|
@@ -12,6 +13,7 @@ export interface IItemProperty<PropertyType> {
|
|
|
12
13
|
readonly modelName: string;
|
|
13
14
|
readonly propertyDef: Static<typeof TProperty> | undefined;
|
|
14
15
|
readonly localStoragePath: string | void;
|
|
16
|
+
readonly localStorageDir: string | void;
|
|
15
17
|
readonly versionLocalId: string | undefined;
|
|
16
18
|
readonly status: any;
|
|
17
19
|
readonly alias: string | undefined;
|
|
@@ -21,5 +23,10 @@ export interface IItemProperty<PropertyType> {
|
|
|
21
23
|
save(): Promise<void>;
|
|
22
24
|
unload(): void;
|
|
23
25
|
getService(): ActorRefFrom<any>;
|
|
26
|
+
find(props: {
|
|
27
|
+
propertyName: string;
|
|
28
|
+
seedLocalId?: string;
|
|
29
|
+
seedUid?: string;
|
|
30
|
+
}): Promise<BaseItemProperty<any> | undefined>;
|
|
24
31
|
}
|
|
25
32
|
//# sourceMappingURL=IItemProperty.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IItemProperty.d.ts","sourceRoot":"","sources":["../../../src/interfaces/IItemProperty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"IItemProperty.d.ts","sourceRoot":"","sources":["../../../src/interfaces/IItemProperty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,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,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC;CAChD"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare class PathResolver {
|
|
2
|
+
private static instance;
|
|
3
|
+
private constructor();
|
|
4
|
+
static getInstance(): PathResolver;
|
|
5
|
+
/**
|
|
6
|
+
* Detects the current environment based on filesystem structure and package.json
|
|
7
|
+
*/
|
|
8
|
+
private detectEnvironment;
|
|
9
|
+
private isInSdkRepo;
|
|
10
|
+
private isUsingLinkedSdk;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the root directory containing node_modules
|
|
13
|
+
*/
|
|
14
|
+
getRootWithNodeModules(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Gets the SDK root directory
|
|
17
|
+
*/
|
|
18
|
+
getSdkRootDir(): string;
|
|
19
|
+
getNodeModulesDir(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Gets the .seed directory path
|
|
22
|
+
*/
|
|
23
|
+
getDotSeedDir(schemaFileDir?: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Gets paths for app-specific directories
|
|
26
|
+
*/
|
|
27
|
+
getAppPaths(schemaFileDir?: string | undefined): {
|
|
28
|
+
sdkRootDir: string;
|
|
29
|
+
dotSeedDir: string;
|
|
30
|
+
nodeModulesDir: string;
|
|
31
|
+
appSchemaDir: string;
|
|
32
|
+
appDbDir: string;
|
|
33
|
+
appMetaDir: string;
|
|
34
|
+
drizzleDbConfigPath: string;
|
|
35
|
+
drizzleKitPath: string;
|
|
36
|
+
templatePath: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=PathResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathResolver.d.ts","sourceRoot":"","sources":["../../../src/node/PathResolver.ts"],"names":[],"mappings":"AAIA,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAc;IACrC,OAAO;IAEP,MAAM,CAAC,WAAW,IAAI,YAAY;IAOlC;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAoBzB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,gBAAgB;IAcxB;;OAEG;IACH,sBAAsB,IAAI,MAAM;IAYhC;;OAEG;IACH,aAAa,IAAI,MAAM;IAmCvB,iBAAiB,IAAI,MAAM;IAa3B;;OAEG;IACH,aAAa,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM;IAO7C;;OAEG;IACH,WAAW,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS;;;;;;;;;;;CA4B/C"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { NODE_APP_DB_CONFIG } from './constants.js';
|
|
4
|
+
|
|
5
|
+
class PathResolver {
|
|
6
|
+
constructor() { }
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!PathResolver.instance) {
|
|
9
|
+
PathResolver.instance = new PathResolver();
|
|
10
|
+
}
|
|
11
|
+
return PathResolver.instance;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Detects the current environment based on filesystem structure and package.json
|
|
15
|
+
*/
|
|
16
|
+
detectEnvironment() {
|
|
17
|
+
// Check if we're in the SDK repo itself
|
|
18
|
+
if (process.env.NODE_ENV !== 'test' && this.isInSdkRepo()) {
|
|
19
|
+
return 'sdk-dev';
|
|
20
|
+
}
|
|
21
|
+
// Check if we're running tests
|
|
22
|
+
if (process.env.NODE_ENV === 'test') {
|
|
23
|
+
return 'test';
|
|
24
|
+
}
|
|
25
|
+
// Check if we're using a linked version of the SDK
|
|
26
|
+
if (this.isUsingLinkedSdk()) {
|
|
27
|
+
return 'linked-sdk';
|
|
28
|
+
}
|
|
29
|
+
// Default to production environment
|
|
30
|
+
return 'production';
|
|
31
|
+
}
|
|
32
|
+
isInSdkRepo() {
|
|
33
|
+
try {
|
|
34
|
+
// Check if we're in the SDK repo by looking for specific SDK files/directories
|
|
35
|
+
const currentDir = process.cwd();
|
|
36
|
+
return fs.existsSync(path.join(currentDir, 'src', 'node')) &&
|
|
37
|
+
fs.existsSync(path.join(currentDir, 'package.json')) &&
|
|
38
|
+
JSON.parse(fs.readFileSync(path.join(currentDir, 'package.json'), 'utf8')).name === '@seedprotocol/sdk';
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
isUsingLinkedSdk() {
|
|
45
|
+
try {
|
|
46
|
+
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
47
|
+
if (!fs.existsSync(pkgPath))
|
|
48
|
+
return false;
|
|
49
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
50
|
+
const sdkDep = pkg.dependencies?.['@seedprotocol/sdk'];
|
|
51
|
+
return sdkDep && (sdkDep.startsWith('link:') || sdkDep.startsWith('portal:'));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets the root directory containing node_modules
|
|
59
|
+
*/
|
|
60
|
+
getRootWithNodeModules() {
|
|
61
|
+
const processCwd = process.cwd();
|
|
62
|
+
const calledFromMocks = processCwd.includes('__mocks__');
|
|
63
|
+
if (calledFromMocks) {
|
|
64
|
+
return path.join(processCwd, '..', '..', '..', '..');
|
|
65
|
+
}
|
|
66
|
+
return processCwd;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets the SDK root directory
|
|
70
|
+
*/
|
|
71
|
+
getSdkRootDir() {
|
|
72
|
+
const env = this.detectEnvironment();
|
|
73
|
+
const rootWithNodeModules = this.getRootWithNodeModules();
|
|
74
|
+
const processCwd = process.cwd();
|
|
75
|
+
if (process.cwd().includes('__mocks__')) {
|
|
76
|
+
return path.join(rootWithNodeModules, 'src');
|
|
77
|
+
}
|
|
78
|
+
if (env === 'linked-sdk') {
|
|
79
|
+
// For linked packages, find the package directory
|
|
80
|
+
const pkgJson = JSON.parse(fs.readFileSync(path.join(processCwd, 'package.json'), 'utf8'));
|
|
81
|
+
const sdkPath = pkgJson.dependencies?.['@seedprotocol/sdk'] || pkgJson.devDependencies?.['@seedprotocol/sdk'];
|
|
82
|
+
console.log(sdkPath);
|
|
83
|
+
if (sdkPath === 'link:@seedprotocol/sdk') {
|
|
84
|
+
return path.join(processCwd, 'node_modules', '@seedprotocol', 'sdk', 'src');
|
|
85
|
+
}
|
|
86
|
+
return path.resolve(processCwd, sdkPath.replace(/^(link:|portal:)/, ''));
|
|
87
|
+
}
|
|
88
|
+
console.log('getSdkRootDir', rootWithNodeModules, env);
|
|
89
|
+
switch (env) {
|
|
90
|
+
case 'sdk-dev':
|
|
91
|
+
// This should be {localDir}/seed-protocol-sdk/src
|
|
92
|
+
return path.join(rootWithNodeModules, 'src');
|
|
93
|
+
case 'test':
|
|
94
|
+
// This should be {localDir}/seed-protocol-sdk/src
|
|
95
|
+
return path.join(rootWithNodeModules, 'src');
|
|
96
|
+
default:
|
|
97
|
+
// This should be {projectDir}/node_modules/@seedprotocol/sdk
|
|
98
|
+
return path.join(rootWithNodeModules, 'node_modules', '@seedprotocol', 'sdk');
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
getNodeModulesDir() {
|
|
102
|
+
const env = this.detectEnvironment();
|
|
103
|
+
const rootWithNodeModules = this.getRootWithNodeModules();
|
|
104
|
+
let nodeModulesDir = path.join(rootWithNodeModules, 'node_modules');
|
|
105
|
+
if (env !== 'linked-sdk' && env !== 'sdk-dev' && nodeModulesDir.includes('__tests__')) {
|
|
106
|
+
nodeModulesDir = path.join(process.cwd(), '..', '..', '..', '..', 'node_modules');
|
|
107
|
+
}
|
|
108
|
+
return nodeModulesDir;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Gets the .seed directory path
|
|
112
|
+
*/
|
|
113
|
+
getDotSeedDir(schemaFileDir) {
|
|
114
|
+
if (!schemaFileDir && process.env.SEED_SDK_TEST_PROJECT_TYPE && !process.cwd().includes('__mocks__')) {
|
|
115
|
+
return path.join(process.cwd(), '__tests__', '__mocks__', process.env.SEED_SDK_TEST_PROJECT_TYPE, 'project', '.seed');
|
|
116
|
+
}
|
|
117
|
+
return path.join(schemaFileDir || process.cwd(), '.seed');
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Gets paths for app-specific directories
|
|
121
|
+
*/
|
|
122
|
+
getAppPaths(schemaFileDir) {
|
|
123
|
+
const env = this.detectEnvironment();
|
|
124
|
+
const dotSeedDir = this.getDotSeedDir(schemaFileDir);
|
|
125
|
+
const nodeModulesDir = this.getNodeModulesDir();
|
|
126
|
+
let drizzleKitPath = path.join(nodeModulesDir, 'drizzle-kit', 'bin.cjs');
|
|
127
|
+
if (env === 'linked-sdk') {
|
|
128
|
+
const sdkRootDir = this.getSdkRootDir();
|
|
129
|
+
console.log(`sdkRootDir: ${sdkRootDir}`);
|
|
130
|
+
const sdkPackageDir = path.dirname(sdkRootDir);
|
|
131
|
+
console.log(`sdkPackageDir: ${sdkPackageDir}`);
|
|
132
|
+
const sdkNodeModulesDir = path.join(sdkPackageDir, 'node_modules');
|
|
133
|
+
drizzleKitPath = path.join(sdkNodeModulesDir, 'drizzle-kit', 'bin.cjs');
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
sdkRootDir: this.getSdkRootDir(),
|
|
137
|
+
dotSeedDir,
|
|
138
|
+
nodeModulesDir,
|
|
139
|
+
appSchemaDir: path.join(dotSeedDir, 'schema'),
|
|
140
|
+
appDbDir: path.join(dotSeedDir, 'db'),
|
|
141
|
+
appMetaDir: path.join(dotSeedDir, 'db', 'meta'),
|
|
142
|
+
drizzleDbConfigPath: path.join(this.getSdkRootDir(), 'node', 'db', NODE_APP_DB_CONFIG),
|
|
143
|
+
drizzleKitPath,
|
|
144
|
+
templatePath: path.join(this.getSdkRootDir(), 'node', 'codegen', 'templates')
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { PathResolver };
|
|
150
|
+
//# sourceMappingURL=PathResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PathResolver.js","sources":["../../../../src/node/PathResolver.ts"],"sourcesContent":["import path from 'path'\nimport fs from 'fs'\nimport { NODE_APP_DB_CONFIG } from './constants'\n\nexport class PathResolver {\n private static instance: PathResolver\n private constructor() {}\n\n static getInstance(): PathResolver {\n if (!PathResolver.instance) {\n PathResolver.instance = new PathResolver()\n }\n return PathResolver.instance\n }\n\n /**\n * Detects the current environment based on filesystem structure and package.json\n */\n private detectEnvironment(): 'sdk-dev' | 'linked-sdk' | 'test' | 'production' {\n // Check if we're in the SDK repo itself\n if (process.env.NODE_ENV !== 'test' && this.isInSdkRepo()) {\n return 'sdk-dev'\n }\n\n // Check if we're running tests\n if (process.env.NODE_ENV === 'test') {\n return 'test'\n }\n\n // Check if we're using a linked version of the SDK\n if (this.isUsingLinkedSdk()) {\n return 'linked-sdk'\n }\n\n // Default to production environment\n return 'production'\n }\n\n private isInSdkRepo(): boolean {\n try {\n // Check if we're in the SDK repo by looking for specific SDK files/directories\n const currentDir = process.cwd()\n return fs.existsSync(path.join(currentDir, 'src', 'node')) &&\n fs.existsSync(path.join(currentDir, 'package.json')) &&\n JSON.parse(fs.readFileSync(path.join(currentDir, 'package.json'), 'utf8')).name === '@seedprotocol/sdk'\n } catch {\n return false\n }\n }\n\n private isUsingLinkedSdk(): boolean {\n try {\n const pkgPath = path.join(process.cwd(), 'package.json')\n if (!fs.existsSync(pkgPath)) return false\n \n const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))\n const sdkDep = pkg.dependencies?.['@seedprotocol/sdk']\n \n return sdkDep && (sdkDep.startsWith('link:') || sdkDep.startsWith('portal:'))\n } catch {\n return false\n }\n }\n\n /**\n * Gets the root directory containing node_modules\n */\n getRootWithNodeModules(): string {\n const processCwd = process.cwd()\n\n const calledFromMocks = processCwd.includes('__mocks__')\n\n if (calledFromMocks) {\n return path.join(processCwd, '..', '..', '..', '..',)\n }\n\n return processCwd\n }\n\n /**\n * Gets the SDK root directory\n */\n getSdkRootDir(): string {\n const env = this.detectEnvironment()\n const rootWithNodeModules = this.getRootWithNodeModules()\n const processCwd = process.cwd()\n\n if (process.cwd().includes('__mocks__')) {\n return path.join(rootWithNodeModules, 'src')\n }\n\n if (env === 'linked-sdk') {\n // For linked packages, find the package directory\n const pkgJson = JSON.parse(fs.readFileSync(path.join(processCwd, 'package.json'), 'utf8'))\n const sdkPath = pkgJson.dependencies?.['@seedprotocol/sdk'] || pkgJson.devDependencies?.['@seedprotocol/sdk']\n console.log(sdkPath)\n if (sdkPath === 'link:@seedprotocol/sdk') {\n return path.join(processCwd, 'node_modules', '@seedprotocol', 'sdk', 'src')\n }\n return path.resolve(processCwd, sdkPath.replace(/^(link:|portal:)/, ''))\n }\n\n console.log('getSdkRootDir', rootWithNodeModules, env)\n\n switch (env) {\n case 'sdk-dev':\n // This should be {localDir}/seed-protocol-sdk/src\n return path.join(rootWithNodeModules, 'src')\n case 'test':\n // This should be {localDir}/seed-protocol-sdk/src\n return path.join(rootWithNodeModules, 'src')\n default:\n // This should be {projectDir}/node_modules/@seedprotocol/sdk\n return path.join(rootWithNodeModules, 'node_modules', '@seedprotocol', 'sdk',)\n }\n }\n\n getNodeModulesDir(): string {\n const env = this.detectEnvironment()\n const rootWithNodeModules = this.getRootWithNodeModules()\n\n let nodeModulesDir = path.join(rootWithNodeModules, 'node_modules')\n\n if (env !== 'linked-sdk' && env !== 'sdk-dev' && nodeModulesDir.includes('__tests__')) {\n nodeModulesDir = path.join(process.cwd(), '..', '..', '..', '..', 'node_modules',)\n }\n\n return nodeModulesDir\n }\n\n /**\n * Gets the .seed directory path\n */\n getDotSeedDir(schemaFileDir?: string): string {\n if (!schemaFileDir && process.env.SEED_SDK_TEST_PROJECT_TYPE && !process.cwd().includes('__mocks__')) {\n return path.join(process.cwd(), '__tests__', '__mocks__', process.env.SEED_SDK_TEST_PROJECT_TYPE, 'project', '.seed')\n }\n return path.join(schemaFileDir || process.cwd(), '.seed')\n }\n\n /**\n * Gets paths for app-specific directories\n */\n getAppPaths(schemaFileDir?: string | undefined) {\n const env = this.detectEnvironment()\n const dotSeedDir = this.getDotSeedDir(schemaFileDir)\n const nodeModulesDir = this.getNodeModulesDir()\n\n let drizzleKitPath = path.join(nodeModulesDir, 'drizzle-kit', 'bin.cjs')\n\n if (env === 'linked-sdk') {\n const sdkRootDir = this.getSdkRootDir()\n console.log(`sdkRootDir: ${sdkRootDir}`)\n const sdkPackageDir = path.dirname(sdkRootDir)\n console.log(`sdkPackageDir: ${sdkPackageDir}`)\n const sdkNodeModulesDir = path.join(sdkPackageDir, 'node_modules')\n drizzleKitPath = path.join(sdkNodeModulesDir, 'drizzle-kit', 'bin.cjs')\n }\n\n return {\n sdkRootDir: this.getSdkRootDir(),\n dotSeedDir,\n nodeModulesDir,\n appSchemaDir: path.join(dotSeedDir, 'schema'),\n appDbDir: path.join(dotSeedDir, 'db'),\n appMetaDir: path.join(dotSeedDir, 'db', 'meta'),\n drizzleDbConfigPath: path.join(this.getSdkRootDir(), 'node', 'db', NODE_APP_DB_CONFIG),\n drizzleKitPath,\n templatePath: path.join(this.getSdkRootDir(), 'node', 'codegen', 'templates')\n }\n }\n} \n"],"names":[],"mappings":";;;;MAIa,YAAY,CAAA;AAEvB,IAAA,WAAA,GAAA;AAEA,IAAA,OAAO,WAAW,GAAA;AAChB,QAAA,IAAI,CAAC,YAAY,CAAC,QAAQ,EAAE;AAC1B,YAAA,YAAY,CAAC,QAAQ,GAAG,IAAI,YAAY,EAAE;;QAE5C,OAAO,YAAY,CAAC,QAAQ;;AAG9B;;AAEG;IACK,iBAAiB,GAAA;;AAEvB,QAAA,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAA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,YAAA,mBAAmB,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,CAAC;YACtF,cAAc;AACd,YAAA,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW;SAC7E;;AAEJ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../../../src/node/codegen/drizzle.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../../../src/node/codegen/drizzle.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAY,SAAS,CAAA;AA4C9C,eAAO,MAAM,yBAAyB,cACzB,MAAM,cACL,cAAc,KACzB,MAgBF,CAAA;AAED,eAAO,MAAM,kCAAkC,mBAC7B,MAAM,GAAG,SAAS,iBACnB,MAAM,GAAG,SAAS,kBA0BlC,CAAA;AA2BD,eAAO,MAAM,iBAAiB,WAAY,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAG,MAY/D,CAAC"}
|
|
@@ -3,13 +3,17 @@ import pluralize from 'pluralize';
|
|
|
3
3
|
import { camelCase, snakeCase } from 'lodash-es';
|
|
4
4
|
import * as nunjucks from 'nunjucks';
|
|
5
5
|
import { SCHEMA_NJK } from '../../helpers/constants.js';
|
|
6
|
-
import { templatePath, dotSeedDir, appGeneratedSchemaDir } from '../constants.js';
|
|
7
6
|
import { getTsImport } from '../helpers/index.js';
|
|
8
7
|
import fs from 'fs';
|
|
8
|
+
import { PathResolver } from '../PathResolver.js';
|
|
9
|
+
import debug from 'debug';
|
|
9
10
|
|
|
11
|
+
const logger = debug('seedSdk:codegen:drizzle');
|
|
10
12
|
const TemplateLoader = {
|
|
11
13
|
getSource: (name) => {
|
|
12
|
-
|
|
14
|
+
const pathResolver = PathResolver.getInstance();
|
|
15
|
+
const { templatePath } = pathResolver.getAppPaths();
|
|
16
|
+
let templateFilePath = templatePath;
|
|
13
17
|
if (name.includes(templatePath)) {
|
|
14
18
|
templateFilePath = name;
|
|
15
19
|
}
|
|
@@ -29,8 +33,16 @@ const env = new nunjucks.Environment(TemplateLoader);
|
|
|
29
33
|
env.addFilter('camelCase', camelCase);
|
|
30
34
|
env.addFilter('snakeCase', snakeCase);
|
|
31
35
|
env.addFilter('pluralize', pluralize);
|
|
36
|
+
const refNamesToExcludeFromRelations = [
|
|
37
|
+
'Text',
|
|
38
|
+
'Number',
|
|
39
|
+
'Boolean',
|
|
40
|
+
'Date',
|
|
41
|
+
];
|
|
32
42
|
const generateDrizzleSchemaCode = (modelName, modelClass) => {
|
|
33
|
-
const listProperties = Object.entries(modelClass.schema).filter(([key, propertyDef]) => propertyDef?.dataType === 'List');
|
|
43
|
+
const listProperties = Object.entries(modelClass.schema).filter(([key, propertyDef]) => propertyDef?.dataType === 'List' && !refNamesToExcludeFromRelations.includes(propertyDef?.ref));
|
|
44
|
+
const pathResolver = PathResolver.getInstance();
|
|
45
|
+
const { templatePath } = pathResolver.getAppPaths();
|
|
34
46
|
const filePath = path.join(templatePath, SCHEMA_NJK);
|
|
35
47
|
const schemaCode = env.render(filePath, {
|
|
36
48
|
modelName,
|
|
@@ -40,9 +52,13 @@ const generateDrizzleSchemaCode = (modelName, modelClass) => {
|
|
|
40
52
|
return schemaCode;
|
|
41
53
|
};
|
|
42
54
|
const createDrizzleSchemaFilesFromConfig = async (configFilePath, outputDirPath) => {
|
|
55
|
+
const pathResolver = PathResolver.getInstance();
|
|
56
|
+
const { dotSeedDir, appSchemaDir } = pathResolver.getAppPaths();
|
|
57
|
+
console.log('createDrizzleSchemaFilesFromConfig', configFilePath, outputDirPath);
|
|
43
58
|
const schemaFilePath = configFilePath || path.join(dotSeedDir, 'schema.ts'); // Developer created file with model definitions
|
|
59
|
+
console.log('schemaFilePath', schemaFilePath);
|
|
44
60
|
const { models, } = await getTsImport(schemaFilePath);
|
|
45
|
-
const writeToDir =
|
|
61
|
+
const writeToDir = appSchemaDir;
|
|
46
62
|
for (const [modelName, modelClass] of Object.entries(models)) {
|
|
47
63
|
const code = generateDrizzleSchemaCode(modelName, modelClass);
|
|
48
64
|
if (!fs.existsSync(writeToDir)) {
|
|
@@ -77,6 +93,11 @@ const seedTypeToJsType = (propertyType) => {
|
|
|
77
93
|
};
|
|
78
94
|
const generateModelCode = (values) => {
|
|
79
95
|
const { modelName, properties } = values;
|
|
96
|
+
const pathResolver = PathResolver.getInstance();
|
|
97
|
+
const { templatePath } = pathResolver.getAppPaths();
|
|
98
|
+
if (modelName === 'Text' || modelName === 'TestModel') {
|
|
99
|
+
logger(`Model name is ${modelName}.`);
|
|
100
|
+
}
|
|
80
101
|
const njkEnv = new nunjucks.Environment(new nunjucks.FileSystemLoader(templatePath));
|
|
81
102
|
njkEnv.addFilter('seedTypeToJsType', seedTypeToJsType);
|
|
82
103
|
return njkEnv.render('model.njk', { modelName, properties });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"drizzle.js","sources":["../../../../../src/node/codegen/drizzle.ts"],"sourcesContent":["import path
|
|
1
|
+
{"version":3,"file":"drizzle.js","sources":["../../../../../src/node/codegen/drizzle.ts"],"sourcesContent":["import path from 'path'\nimport pluralize from 'pluralize'\nimport { camelCase, snakeCase } from 'lodash-es'\nimport * as nunjucks from 'nunjucks'\nimport { ILoader } from 'nunjucks'\nimport { ModelClassType } from '@/types'\nimport { SCHEMA_NJK } from '@/helpers/constants'\nimport { getTsImport } from '@/node/helpers'\nimport fs from 'fs'\nimport {PathResolver} from '@/node/PathResolver'\nimport debug from 'debug'\n\nconst logger = debug('seedSdk:codegen:drizzle')\n\n\nconst TemplateLoader: ILoader = {\n getSource: (name: string) => {\n const pathResolver = PathResolver.getInstance()\n const { templatePath } = pathResolver.getAppPaths()\n let templateFilePath = templatePath\n if (name.includes(templatePath)) {\n templateFilePath = name\n } else {\n templateFilePath = path.join(templatePath, path.basename(name))\n }\n const src = fs.readFileSync(templateFilePath, 'utf-8')\n\n return {\n path: name,\n src,\n noCache: false,\n }\n },\n}\n\n// Configure Nunjucks\nconst env = new nunjucks.Environment(TemplateLoader)\n\nenv.addFilter('camelCase', camelCase)\nenv.addFilter('snakeCase', snakeCase)\nenv.addFilter('pluralize', pluralize)\n\nconst refNamesToExcludeFromRelations = [\n 'Text',\n 'Number',\n 'Boolean',\n 'Date',\n]\n\nexport const generateDrizzleSchemaCode = (\n modelName: string,\n modelClass: ModelClassType,\n): string => {\n const listProperties = Object.entries(modelClass.schema).filter(\n ([key, propertyDef]) => propertyDef?.dataType === 'List' && !refNamesToExcludeFromRelations.includes(propertyDef?.ref!),\n )\n\n const pathResolver = PathResolver.getInstance()\n const { templatePath } = pathResolver.getAppPaths()\n const filePath = path.join(templatePath, SCHEMA_NJK)\n\n const schemaCode = env.render(filePath, {\n modelName,\n modelClass,\n listProperties,\n })\n\n return schemaCode\n}\n\nexport const createDrizzleSchemaFilesFromConfig = async (\n configFilePath: string | undefined,\n outputDirPath: string | undefined,\n) => {\n const pathResolver = PathResolver.getInstance()\n const { dotSeedDir, appSchemaDir } = pathResolver.getAppPaths()\n console.log('createDrizzleSchemaFilesFromConfig', configFilePath, outputDirPath)\n\n const schemaFilePath = configFilePath || path.join(dotSeedDir, 'schema.ts') // Developer created file with model definitions\n console.log('schemaFilePath', schemaFilePath)\n\n const { models, } = await getTsImport<{\n models: Record<string, ModelClassType>\n }>(schemaFilePath)\n\n const writeToDir = outputDirPath || appSchemaDir\n\n for (const [modelName, modelClass] of Object.entries(models)) {\n const code = generateDrizzleSchemaCode(modelName, modelClass)\n\n if (!fs.existsSync(writeToDir)) {\n fs.mkdirSync(writeToDir)\n }\n\n const filePath = path.join(writeToDir, `${modelName}Schema.ts`)\n\n await fs.promises.writeFile(filePath, code).catch((e) => console.error(e))\n }\n}\n\n // Helper to determine TypeScript type based on property type\n const seedTypeToJsType = (propertyType: string): string => {\n switch (propertyType) {\n case 'Text':\n return 'string';\n case 'Number':\n return 'number';\n case 'Boolean':\n return 'boolean';\n case 'Date':\n return 'string';\n case 'List':\n return 'string[]';\n case 'Relation':\n return 'string';\n case 'Image':\n return 'string';\n case 'File':\n return 'string';\n default:\n return 'any';\n }\n};\n\n\nexport const generateModelCode = (values: Record<string, any>): string => {\n const { modelName, properties } = values;\n const pathResolver = PathResolver.getInstance()\n const { templatePath } = pathResolver.getAppPaths()\n\n if (modelName === 'Text' || modelName === 'TestModel') {\n logger(`Model name is ${modelName}.`)\n }\n\n const njkEnv = new nunjucks.Environment(new nunjucks.FileSystemLoader(templatePath))\n njkEnv.addFilter('seedTypeToJsType', seedTypeToJsType)\n return njkEnv.render('model.njk', { modelName, properties })\n};\n"],"names":[],"mappings":";;;;;;;;;;AAYA,MAAM,MAAM,GAAG,KAAK,CAAC,yBAAyB,CAAC;AAG/C,MAAM,cAAc,GAAY;AAC9B,IAAA,SAAS,EAAE,CAAC,IAAY,KAAI;AAC1B,QAAA,MAAM,YAAY,GAAG,YAAY,CAAC,WAAW,EAAE;QAC/C,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,WAAW,EAAE;QACnD,IAAI,gBAAgB,GAAG,YAAY;AACnC,QAAA,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YAC/B,gBAAgB,GAAG,IAAI;;aAClB;AACL,YAAA,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;;QAEjE,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,gBAAgB,EAAE,OAAO,CAAC;QAEtD,OAAO;AACL,YAAA,IAAI,EAAE,IAAI;YACV,GAAG;AACH,YAAA,OAAO,EAAE,KAAK;SACf;KACF;CACF;AAED;AACA,MAAM,GAAG,GAAG,IAAI,QAAQ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;;AAElB,CAAC;AAGY,MAAA,iBAAiB,GAAG,CAAC,MAA2B,KAAY;AACvE,IAAA,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,MAAM;AACxC,IAAA,MAAM,YAAY,GAAG,YAAY,CAAC,WAAW,EAAE;IAC/C,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAC,WAAW,EAAE;IAEnD,IAAI,SAAS,KAAK,MAAM,IAAI,SAAS,KAAK,WAAW,EAAE;AACrD,QAAA,MAAM,CAAC,CAAA,cAAA,EAAiB,SAAS,CAAA,CAAA,CAAG,CAAC;;AAGvC,IAAA,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,WAAW,CAAC,IAAI,QAAQ,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;AACpF,IAAA,MAAM,CAAC,SAAS,CAAC,kBAAkB,EAAE,gBAAgB,CAAC;AACtD,IAAA,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;AAC9D;;;;"}
|
|
@@ -1,14 +1,3 @@
|
|
|
1
1
|
import 'dotenv/config';
|
|
2
2
|
export declare const NODE_APP_DB_CONFIG = "node.app.db.config.ts";
|
|
3
|
-
declare let rootWithNodeModules: string;
|
|
4
|
-
declare let sdkRootDir: string;
|
|
5
|
-
declare let dotSeedDir: string;
|
|
6
|
-
export declare const drizzleKitPath: string;
|
|
7
|
-
export declare const appSchemaDir: string;
|
|
8
|
-
export declare const appDbDir: string;
|
|
9
|
-
export declare const appMetaDir: string;
|
|
10
|
-
export declare const appGeneratedSchemaDir: string;
|
|
11
|
-
export declare const drizzleDbConfigPath: string;
|
|
12
|
-
export declare const templatePath: string;
|
|
13
|
-
export { rootWithNodeModules, sdkRootDir, dotSeedDir };
|
|
14
3
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/node/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/node/constants.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AAEtB,eAAO,MAAM,kBAAkB,0BAA0B,CAAA"}
|
|
@@ -1,37 +1,6 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import 'dotenv/config';
|
|
3
|
-
import process from 'node:process';
|
|
4
2
|
|
|
5
3
|
const NODE_APP_DB_CONFIG = 'node.app.db.config.ts';
|
|
6
|
-
console.log('process.env.IS_SEED_DEV', process.env.IS_SEED_DEV);
|
|
7
|
-
const currentDir = path.dirname(new URL(import.meta.url).pathname);
|
|
8
|
-
console.log('currentDir', currentDir);
|
|
9
|
-
const parentToCheck = path.join(currentDir, '..');
|
|
10
|
-
console.log('parentToCheck', parentToCheck);
|
|
11
|
-
let rootWithNodeModules = path.join(currentDir, '..', '..', '..', '..', '..', '..');
|
|
12
|
-
if (process.env.IS_PORTAL) {
|
|
13
|
-
rootWithNodeModules = process.cwd();
|
|
14
|
-
}
|
|
15
|
-
if (process.env.IS_SEED_DEV || process.env.NODE_ENV === 'test') {
|
|
16
|
-
rootWithNodeModules = path.join(parentToCheck, '..');
|
|
17
|
-
}
|
|
18
|
-
console.log('rootWithNodeModules', rootWithNodeModules);
|
|
19
|
-
let sdkRootDir = path.join(rootWithNodeModules, 'node_modules', '@seedprotocol', 'sdk', 'dist');
|
|
20
|
-
if (process.env.IS_SEED_DEV) {
|
|
21
|
-
sdkRootDir = path.join(rootWithNodeModules, 'src');
|
|
22
|
-
}
|
|
23
|
-
let dotSeedDir = path.join(rootWithNodeModules, '.seed');
|
|
24
|
-
if (process.env.IS_SEED_DEV || process.env.NODE_ENV === 'test') {
|
|
25
|
-
dotSeedDir = path.join(process.cwd(), '__tests__', '__mocks__', 'node', 'project', '.seed');
|
|
26
|
-
}
|
|
27
|
-
const drizzleKitPath = path.join(rootWithNodeModules, 'node_modules', 'drizzle-kit', 'bin.cjs');
|
|
28
|
-
// App file paths. These are the single source of truth for the SDK user's data model
|
|
29
|
-
const appSchemaDir = path.join(dotSeedDir, 'schema');
|
|
30
|
-
const appDbDir = path.join(dotSeedDir, 'db');
|
|
31
|
-
const appMetaDir = path.join(appDbDir, 'meta');
|
|
32
|
-
const appGeneratedSchemaDir = path.join(dotSeedDir, 'schema');
|
|
33
|
-
const drizzleDbConfigPath = path.join(sdkRootDir, 'node', 'db', NODE_APP_DB_CONFIG);
|
|
34
|
-
const templatePath = path.join(sdkRootDir, 'node', 'codegen', 'templates');
|
|
35
4
|
|
|
36
|
-
export { NODE_APP_DB_CONFIG
|
|
5
|
+
export { NODE_APP_DB_CONFIG };
|
|
37
6
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../../src/node/constants.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/node/constants.ts"],"sourcesContent":["import 'dotenv/config'\n\nexport const NODE_APP_DB_CONFIG = 'node.app.db.config.ts'\n\n\n\n"],"names":[],"mappings":";;AAEO,MAAM,kBAAkB,GAAG;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.app.db.config.d.ts","sourceRoot":"","sources":["../../../../src/node/db/node.app.db.config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node.app.db.config.d.ts","sourceRoot":"","sources":["../../../../src/node/db/node.app.db.config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;wBAmBrC,aAAa;AAPnB,wBAOmB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../../src/schema/image/model.ts"],"names":[],"mappings":"AAEA,cACM,KAAK;IACD,oBAAoB,EAAG,MAAM,CAAA;IAC7B,GAAG,EAAG,MAAM,CAAA;IACZ,GAAG,EAAG,MAAM,CAAA;IACZ,GAAG,EAAG,MAAM,CAAA;CACrB;AAED,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
import { Model } from '../model/index.js';
|
|
4
|
+
import { Text } from '../property/index.js';
|
|
5
|
+
|
|
6
|
+
let Image = class Image {
|
|
7
|
+
};
|
|
8
|
+
__decorate([
|
|
9
|
+
Text(),
|
|
10
|
+
__metadata("design:type", String)
|
|
11
|
+
], Image.prototype, "storageTransactionId", void 0);
|
|
12
|
+
__decorate([
|
|
13
|
+
Text(),
|
|
14
|
+
__metadata("design:type", String)
|
|
15
|
+
], Image.prototype, "uri", void 0);
|
|
16
|
+
__decorate([
|
|
17
|
+
Text(),
|
|
18
|
+
__metadata("design:type", String)
|
|
19
|
+
], Image.prototype, "alt", void 0);
|
|
20
|
+
__decorate([
|
|
21
|
+
Text(),
|
|
22
|
+
__metadata("design:type", String)
|
|
23
|
+
], Image.prototype, "src", void 0);
|
|
24
|
+
Image = __decorate([
|
|
25
|
+
Model
|
|
26
|
+
], Image);
|
|
27
|
+
|
|
28
|
+
export { Image };
|
|
29
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sources":["../../../../../src/schema/image/model.ts"],"sourcesContent":["import { Model, Text } from '@/schema'\n\n@Model\nclass Image {\n @Text() storageTransactionId!: string\n @Text() uri!: string\n @Text() alt!: string\n @Text() src!: string\n}\n\nexport { Image }\n"],"names":[],"mappings":";;;;;AAGM,IAAA,KAAK,GAAX,MAAM,KAAK,CAAA;;AACD,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAA8B,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,sBAAA,EAAA,MAAA,CAAA;AAC7B,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,KAAA,EAAA,MAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,KAAA,EAAA,MAAA,CAAA;AACZ,UAAA,CAAA;AAAP,IAAA,IAAI,EAAE;;AAAa,CAAA,EAAA,KAAA,CAAA,SAAA,EAAA,KAAA,EAAA,MAAA,CAAA;AAJhB,KAAK,GAAA,UAAA,CAAA;IADV;AACK,CAAA,EAAA,KAAK,CAKV;;;;"}
|