@seedprotocol/sdk 0.3.11 → 0.3.13

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C,cAAc,mCAAmC,CAAA;AACjD,cAAc,2BAA2B,CAAA;AACzC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAO7C,eAAO,MAAM,UAAU,QAAO,MAE7B,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,MAAM,WAEtC,CAAA;AAED,eAAO,MAAM,cAAc,QAAS,MAAM,iEA2BzC,CAAA;AAED,eAAO,MAAM,WAAW,WAAY,MAAM,kBAWzC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,YAe1B,CAAA;AAED,eAAO,MAAM,qBAAqB,SAC1B,MAAM,KACX,aAAa,GAAG,QAAQ,GAAG,KAAK,GAAG,IAwBrC,CAAA;AAED,eAAO,MAAM,kBAAkB,SACvB,MAAM,KACX,OAAO,CAAC,MAAM,GAAG,SAAS,CAc5B,CAAA;AAED,eAAO,MAAM,gBAAgB,2CAI5B,CAAA;AAED,eAAO,MAAM,qBAAqB,WAAY,MAAM,WACF,CAAA;AAElD,eAAO,MAAM,4BAA4B,oBAAqB,MAAM;;;;CAiBnE,CAAA;AAED,eAAO,MAAM,cAAc,SACnB,OAAO,KACZ,OAAO,CAAC,MAAM,CAEhB,CAAA;AAyBD,eAAO,MAAM,QAAQ,gBAAiB,WAAW,KAAG,OAwBnD,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/helpers/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAa,MAAkB,SAAS,CAAA;AAGxD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAG9C,cAAc,mCAAmC,CAAA;AACjD,cAAc,2BAA2B,CAAA;AACzC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAM7C,eAAO,MAAM,UAAU,QAAO,MAE7B,CAAA;AAED,eAAO,MAAM,WAAW,QAAS,MAAM,WAEtC,CAAA;AAED,eAAO,MAAM,cAAc,QAAS,MAAM,iEA2BzC,CAAA;AAED,eAAO,MAAM,WAAW,WAAY,MAAM,kBAWzC,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,YAe1B,CAAA;AAED,eAAO,MAAM,qBAAqB,SAC1B,MAAM,KACX,aAAa,GAAG,QAAQ,GAAG,KAAK,GAAG,IAwBrC,CAAA;AAED,eAAO,MAAM,kBAAkB,SACvB,MAAM,KACX,OAAO,CAAC,MAAM,GAAG,SAAS,CAc5B,CAAA;AAED,eAAO,MAAM,gBAAgB,2CAI5B,CAAA;AAED,eAAO,MAAM,qBAAqB,WAAY,MAAM,WACF,CAAA;AAElD,eAAO,MAAM,4BAA4B,oBAAqB,MAAM;;;;CAiBnE,CAAA;AAED,eAAO,MAAM,cAAc,SACnB,OAAO,KACZ,OAAO,CAAC,MAAM,CAEhB,CAAA;AAyBD,eAAO,MAAM,QAAQ,gBAAiB,WAAW,KAAG,OAwBnD,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { customAlphabet } from 'nanoid';
2
- import * as sha3 from 'js-sha3';
2
+ import { sha3_256 } from 'js-sha3';
3
3
  import * as nanoIdDictionary from 'nanoid-dictionary';
4
4
  import debug from 'debug';
5
5
  import { BaseFileManager } from './FileManager/BaseFileManager.js';
@@ -7,7 +7,6 @@ import 'graphql-request';
7
7
  import '../services/internal/constants.js';
8
8
 
9
9
  const logger = debug('seedSdk:shared:helpers');
10
- const { sha3_256, } = sha3;
11
10
  const { alphanumeric } = nanoIdDictionary;
12
11
  const generateId = () => {
13
12
  return customAlphabet(alphanumeric, 10)();
@@ -1 +1 @@
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,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AQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACvB,QAAA,OAAO,KAAK;;AAGd,IAAA,OAAO,IAAI;AACb;MAEa,kBAAkB,GAAG,OAChC,IAAY,KACmB;AAC/B,IAAA,MAAM,aAAa,GAAG,CAAiB,cAAA,EAAA,IAAI,EAAE;IAC7C,MAAM,UAAU,GAAG,MAAM,eAAe,CAAC,UAAU,CAAC,aAAa,CAAC;IAClE,IAAI,CAAC,UAAU,EAAE;AACf,QAAA,MAAM,CAAC,CAAA,yBAAA,EAA4B,aAAa,CAAA,eAAA,CAAiB,CAAC;QAClE;;IAEF,MAAM,MAAM,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;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../../src/helpers/index.ts"],"sourcesContent":["import { customAlphabet } from 'nanoid'\nimport { Message, sha3_256, } 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\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":";;;;;;;;AAWA,MAAM,MAAM,GAAG,KAAK,CAAC,wBAAwB,CAAC;AAG9C,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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AAG,MAAM,eAAe,CAAC,UAAU,CAAC,aAAa,CAAC;IAClE,IAAI,CAAC,UAAU,EAAE;AACf,QAAA,MAAM,CAAC,CAAA,yBAAA,EAA4B,aAAa,CAAA,eAAA,CAAiB,CAAC;QAClE;;IAEF,MAAM,MAAM,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;;;;"}
@@ -8,7 +8,7 @@ import fs from 'fs';
8
8
  import { PathResolver } from '../PathResolver.js';
9
9
  import debug from 'debug';
10
10
 
11
- const logger = debug('seedSdk:codegen:drizzle');
11
+ debug('seedSdk:codegen:drizzle');
12
12
  const TemplateLoader = {
13
13
  getSource: (name) => {
14
14
  const pathResolver = PathResolver.getInstance();
@@ -68,40 +68,6 @@ const createDrizzleSchemaFilesFromConfig = async (configFilePath, outputDirPath)
68
68
  await fs.promises.writeFile(filePath, code).catch((e) => console.error(e));
69
69
  }
70
70
  };
71
- // Helper to determine TypeScript type based on property type
72
- const seedTypeToJsType = (propertyType) => {
73
- switch (propertyType) {
74
- case 'Text':
75
- return 'string';
76
- case 'Number':
77
- return 'number';
78
- case 'Boolean':
79
- return 'boolean';
80
- case 'Date':
81
- return 'string';
82
- case 'List':
83
- return 'string[]';
84
- case 'Relation':
85
- return 'string';
86
- case 'Image':
87
- return 'string';
88
- case 'File':
89
- return 'string';
90
- default:
91
- return 'any';
92
- }
93
- };
94
- const generateModelCode = (values) => {
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
- }
101
- const njkEnv = new nunjucks.Environment(new nunjucks.FileSystemLoader(templatePath));
102
- njkEnv.addFilter('seedTypeToJsType', seedTypeToJsType);
103
- return njkEnv.render('model.njk', { modelName, properties });
104
- };
105
71
 
106
- export { createDrizzleSchemaFilesFromConfig, generateDrizzleSchemaCode, generateModelCode };
72
+ export { createDrizzleSchemaFilesFromConfig, generateDrizzleSchemaCode };
107
73
  //# sourceMappingURL=drizzle.js.map
@@ -1 +1 @@
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,CAAC,WAAW,CAAC,cAAc,CAAC;AAEpD,GAAG,CAAC,SA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,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
+ {"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":";;;;;;;;;;AAYe,KAAK,CAAC,yBAAyB;AAG9C,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,CAAC,WAAW,CAAC,cAAc,CAAC;AAEpD,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,CAAC;AACrC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,CAAC;AACrC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,SAAS,CAAC;AAErC,MAAM,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AK,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;QAC5D,MAAM,IAAI,GAAG,yBAAyB,CAAC,SAAS,EAAE,UAAU,CAAC;QAE7D,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;AAC9B,YAAA,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC;;AAG1B,QAAA,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAG,EAAA,SAAS,CAAW,SAAA,CAAA,CAAC;QAE/D,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;;AAE9E;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seedprotocol/sdk",
3
- "version": "0.3.11",
3
+ "version": "0.3.13",
4
4
  "description": "The SDK for Seed Protocol",
5
5
  "type": "module",
6
6
  "engines": {
@@ -41,7 +41,6 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@ethereum-attestation-service/eas-sdk": "^2.7.0",
44
- "@ethersproject/providers": "^5.7.2",
45
44
  "@libsql/client": "^0.14.0",
46
45
  "@misskey-dev/browser-image-resizer": "^2024.1.0",
47
46
  "@pianity/arsnap-adapter": "^0.2.0",
@@ -51,8 +50,6 @@
51
50
  "@tanstack/query-sync-storage-persister": "^5.62.8",
52
51
  "@tanstack/react-query-devtools": "^5.62.8",
53
52
  "@tanstack/react-query-persist-client": "^5.62.8",
54
- "@tanstack/react-virtual": "^3.11.2",
55
- "@vitejs/plugin-legacy": "^6.0.0",
56
53
  "@xstate/react": "^5.0.0",
57
54
  "arweave": "^1.15.5",
58
55
  "crypto-browserify": "^3.12.1",
@@ -73,7 +70,6 @@
73
70
  "nunjucks": "^3.2.4",
74
71
  "path-browserify": "^1.0.1",
75
72
  "pluralize": "^8.0.0",
76
- "promise-async": "^0.2.0",
77
73
  "protobufjs": "^7.4.0",
78
74
  "reflect-metadata": "^0.2.2",
79
75
  "rimraf": "^6.0.1",
package/dist/addModel.js DELETED
@@ -1,93 +0,0 @@
1
- #!/usr/bin/env node
2
- import fs from 'fs';
3
- import { generateModelCode } from './src/node/codegen/drizzle.js';
4
-
5
- // Parse command line arguments
6
- const args = process.argv.slice(2);
7
- const sourceSchemaFilePath = args[0];
8
- const outputFilePath = args[1];
9
- const jsonString = args[2];
10
- if (!sourceSchemaFilePath || !outputFilePath || !jsonString) {
11
- console.error('Usage: npx tsx bin/addModel.ts <source-schema-file-path> <output-file-path> <json-string>');
12
- process.exit(1);
13
- }
14
- // Read the contents of the file
15
- let fileContents;
16
- try {
17
- fileContents = fs.readFileSync(sourceSchemaFilePath, 'utf-8');
18
- }
19
- catch (error) {
20
- console.error(`Error reading file at ${sourceSchemaFilePath}:`, error);
21
- process.exit(1);
22
- }
23
- // Parse the JSON string
24
- let jsonModel;
25
- try {
26
- jsonModel = JSON.parse(jsonString);
27
- }
28
- catch (error) {
29
- console.error('Invalid JSON string:', error);
30
- process.exit(1);
31
- }
32
- /**
33
- * Simple function to inject a new model after the last model class and update the models object
34
- * @param {string} schemaContent - The content of the schema file
35
- * @param {string} newModelCode - The code for the new model to inject
36
- * @returns {string} The updated schema content
37
- */
38
- const injectModel = (schemaContent, newModelCode) => {
39
- // Extract the model name from the new code
40
- const modelNameMatch = newModelCode.match(/class\s+(\w+)/);
41
- if (!modelNameMatch) {
42
- throw new Error("Could not extract model name from provided code");
43
- }
44
- const modelName = modelNameMatch[1];
45
- // Find the 'const models' position
46
- const modelsPos = schemaContent.indexOf('const models');
47
- if (modelsPos === -1) {
48
- throw new Error("Could not find 'const models' in the schema");
49
- }
50
- // Find the position of the last model class before 'const models'
51
- const lastClassPos = schemaContent.lastIndexOf('@Model', modelsPos);
52
- if (lastClassPos === -1) {
53
- throw new Error("Could not find any model declarations in the schema");
54
- }
55
- // Find the end of the last class
56
- const classEndPos = schemaContent.indexOf('}', lastClassPos);
57
- if (classEndPos === -1) {
58
- throw new Error("Could not find closing brace of the last model class");
59
- }
60
- // Find the position after the last class's closing brace
61
- const insertModelPos = schemaContent.indexOf('\n', classEndPos) + 1;
62
- // Insert the new model
63
- let updatedSchema = schemaContent.slice(0, insertModelPos) +
64
- "\n" + newModelCode + "\n\n" +
65
- schemaContent.slice(insertModelPos);
66
- // Find the closing brace of the models object
67
- const modelsClosingBracePos = updatedSchema.indexOf('}', updatedSchema.indexOf('const models'));
68
- // Add the new model to the models object
69
- updatedSchema =
70
- updatedSchema.slice(0, modelsClosingBracePos) +
71
- ` ${modelName},\n` +
72
- updatedSchema.slice(modelsClosingBracePos);
73
- return updatedSchema;
74
- };
75
- if (fileContents.includes(`class ${jsonModel.name}`)) {
76
- console.error(`Model with name ${jsonModel.name} already exists in the schema`);
77
- process.exit(0);
78
- }
79
- const newModelCode = generateModelCode({
80
- modelName: jsonModel.name,
81
- properties: jsonModel.properties,
82
- });
83
- const updatedSchema = injectModel(fileContents, newModelCode);
84
- // Write the new table file
85
- try {
86
- fs.writeFileSync(outputFilePath, updatedSchema, 'utf-8');
87
- console.log(`Wrote updated schema file to ${outputFilePath}`);
88
- }
89
- catch (error) {
90
- console.error('Error writing Drizzle table file:', error);
91
- process.exit(1);
92
- }
93
- //# sourceMappingURL=addModel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addModel.js","sources":["../../scripts/addModel.ts"],"sourcesContent":["#!/usr/bin/env node\n\nimport fs from 'fs';\nimport { generateModelCode } from '../src/node/codegen/drizzle';\n\n// Parse command line arguments\nconst args = process.argv.slice(2);\nconst sourceSchemaFilePath = args[0];\nconst outputFilePath = args[1];\nconst jsonString = args[2];\n\nif (!sourceSchemaFilePath || !outputFilePath || !jsonString) {\n console.error('Usage: npx tsx bin/addModel.ts <source-schema-file-path> <output-file-path> <json-string>');\n process.exit(1);\n}\n\n// Read the contents of the file\nlet fileContents;\ntry {\n fileContents = fs.readFileSync(sourceSchemaFilePath, 'utf-8');\n} catch (error) {\n console.error(`Error reading file at ${sourceSchemaFilePath}:`, error);\n process.exit(1);\n}\n\n// Parse the JSON string\nlet jsonModel;\ntry {\n jsonModel = JSON.parse(jsonString);\n} catch (error) {\n console.error('Invalid JSON string:', error);\n process.exit(1);\n}\n\n/**\n * Simple function to inject a new model after the last model class and update the models object\n * @param {string} schemaContent - The content of the schema file\n * @param {string} newModelCode - The code for the new model to inject\n * @returns {string} The updated schema content\n */\nconst injectModel = (schemaContent: string, newModelCode: string) => {\n // Extract the model name from the new code\n const modelNameMatch = newModelCode.match(/class\\s+(\\w+)/);\n if (!modelNameMatch) {\n throw new Error(\"Could not extract model name from provided code\");\n }\n const modelName = modelNameMatch[1];\n\n // Find the 'const models' position\n const modelsPos = schemaContent.indexOf('const models');\n if (modelsPos === -1) {\n throw new Error(\"Could not find 'const models' in the schema\");\n }\n\n // Find the position of the last model class before 'const models'\n const lastClassPos = schemaContent.lastIndexOf('@Model', modelsPos);\n if (lastClassPos === -1) {\n throw new Error(\"Could not find any model declarations in the schema\");\n }\n\n // Find the end of the last class\n const classEndPos = schemaContent.indexOf('}', lastClassPos);\n if (classEndPos === -1) {\n throw new Error(\"Could not find closing brace of the last model class\");\n }\n\n // Find the position after the last class's closing brace\n const insertModelPos = schemaContent.indexOf('\\n', classEndPos) + 1;\n \n // Insert the new model\n let updatedSchema = \n schemaContent.slice(0, insertModelPos) + \n \"\\n\" + newModelCode + \"\\n\\n\" + \n schemaContent.slice(insertModelPos);\n \n // Find the closing brace of the models object\n const modelsClosingBracePos = updatedSchema.indexOf('}', updatedSchema.indexOf('const models'));\n \n // Add the new model to the models object\n updatedSchema = \n updatedSchema.slice(0, modelsClosingBracePos) + \n ` ${modelName},\\n` + \n updatedSchema.slice(modelsClosingBracePos);\n \n return updatedSchema;\n}\n\nif (fileContents.includes(`class ${jsonModel.name}`)) {\n console.error(`Model with name ${jsonModel.name} already exists in the schema`);\n process.exit(0);\n}\n\nconst newModelCode = generateModelCode({\n modelName: jsonModel.name,\n properties: jsonModel.properties,\n});\n\nconst updatedSchema = injectModel(fileContents, newModelCode);\n\n// Write the new table file\ntry {\n fs.writeFileSync(outputFilePath, updatedSchema, 'utf-8');\n console.log(`Wrote updated schema file to ${outputFilePath}`);\n} catch (error) {\n console.error('Error writing Drizzle table file:', error);\n process.exit(1);\n} \n"],"names":[],"mappings":";;;;AAKA;AACA,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AAClC,MAAM,oBAAoB,GAAG,IAAI,CAAC,CAAC,CAAC;AACpC,MAAM,cAAc,GAAG,IAAI,CAAC,CAAC,CAAC;AAC9B,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC;AAE1B,IAAI,CAAC,oBAAoB,IAAI,CAAC,cAAc,IAAI,CAAC,UAAU,EAAE;AAC3D,IAAA,OAAO,CAAC,KAAK,CAAC,2FAA2F,CAAC;AAC1G,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB;AAEA;AACA,IAAI,YAAY;AAChB,IAAI;IACF,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,oBAAoB,EAAE,OAAO,CAAC;AAC/D;AAAE,OAAO,KAAK,EAAE;IACd,OAAO,CAAC,KAAK,CAAC,CAAA,sBAAA,EAAyB,oBAAoB,CAAG,CAAA,CAAA,EAAE,KAAK,CAAC;AACtE,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB;AAEA;AACA,IAAI,SAAS;AACb,IAAI;AACF,IAAA,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;AACpC;AAAE,OAAO,KAAK,EAAE;AACd,IAAA,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC;AAC5C,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB;AAEA;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,SAAS,CAAK,GAAA,CAAA;AACnB,YAAA,aAAa,CAAC,KAAK,CAAC,qBAAqB,CAAC;AAE5C,IAAA,OAAO,aAAa;AACtB,CAAC;AAED,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAA,MAAA,EAAS,SAAS,CAAC,IAAI,CAAA,CAAE,CAAC,EAAE;IACpD,OAAO,CAAC,KAAK,CAAC,CAAA,gBAAA,EAAmB,SAAS,CAAC,IAAI,CAA+B,6BAAA,CAAA,CAAC;AAC/E,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB;AAEA,MAAM,YAAY,GAAG,iBAAiB,CAAC;IACrC,SAAS,EAAE,SAAS,CAAC,IAAI;IACzB,UAAU,EAAE,SAAS,CAAC,UAAU;AACjC,CAAA,CAAC;AAEF,MAAM,aAAa,GAAG,WAAW,CAAC,YAAY,EAAE,YAAY,CAAC;AAE7D;AACA,IAAI;IACF,EAAE,CAAC,aAAa,CAAC,cAAc,EAAE,aAAa,EAAE,OAAO,CAAC;AACxD,IAAA,OAAO,CAAC,GAAG,CAAC,gCAAgC,cAAc,CAAA,CAAE,CAAC;AAC/D;AAAE,OAAO,KAAK,EAAE;AACd,IAAA,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC;AACzD,IAAA,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AACjB"}
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
3
- //# sourceMappingURL=addModel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addModel.d.ts","sourceRoot":"","sources":["../../scripts/addModel.ts"],"names":[],"mappings":""}