@ragestudio/scylla-odm 0.10.3 → 0.12.0

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/client.d.ts CHANGED
@@ -9,6 +9,7 @@ declare class Client {
9
9
  driver: Client$1;
10
10
  mapper: mapping.Mapper;
11
11
  models: Map<string, Model<any>>;
12
+ model(name: string): Model<any> | undefined;
12
13
  initialize(options?: {
13
14
  sync?: boolean;
14
15
  }): Promise<void>;
package/client.js CHANGED
@@ -33,6 +33,9 @@ var Client = class {
33
33
  driver;
34
34
  mapper;
35
35
  models = /* @__PURE__ */ new Map();
36
+ model(name) {
37
+ return this.models.get(name);
38
+ }
36
39
  async initialize(options = {}) {
37
40
  let models;
38
41
  try {
package/client.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":["loadModels","buildMapper"],"sources":["../src/client.ts"],"sourcesContent":["import type {\n\tClient as T_CassandraClient,\n\tClientOptions as T_CassandraClientOptions,\n\tmapping as T_CassandraMapping,\n} from \"cassandra-driver\"\nimport type { ClientConfig } from \"./types\"\n\n//@ts-ignore\nimport path from \"node:path\"\n//@ts-ignore\nimport Cassandra from \"cassandra-driver\"\nimport loadModels from \"./utils/loadModels\"\nimport buildMapper from \"./utils/buildMapper\"\n\nimport { Model } from \"./model\"\nimport { InferDocument } from \"./types\"\n\nconst DEFAULT_MAX_RETRIES = 3\nconst DEFAULT_RETRY_DELAY = 1000\nconst { SCYLLA_CONTACT_POINTS, SCYLLA_LOCAL_DATA_CENTER, SCYLLA_KEYSPACE } =\n\tprocess.env\n\nexport class Client {\n\tconstructor(config: ClientConfig = {}) {\n\t\tif (globalThis.__scylla_client) {\n\t\t\tthrow new Error(\n\t\t\t\t\"An instance of Scylla Client is already initialized\",\n\t\t\t)\n\t\t}\n\n\t\tthis.config = {\n\t\t\tmodelsPath: path.resolve(process.cwd(), \"db\"),\n\t\t\tcontactPoints:\n\t\t\t\t(config.contactPoints ?? SCYLLA_CONTACT_POINTS)\n\t\t\t\t\t? SCYLLA_CONTACT_POINTS.split(\",\")\n\t\t\t\t\t: [\"127.0.0.1\"],\n\t\t\tlocalDataCenter:\n\t\t\t\tconfig.localDataCenter ??\n\t\t\t\tSCYLLA_LOCAL_DATA_CENTER ??\n\t\t\t\t\"datacenter1\",\n\t\t\tkeyspace: config.keyspace ?? SCYLLA_KEYSPACE ?? \"default\",\n\t\t\tport: 9042,\n\t\t\tmaxRetries: DEFAULT_MAX_RETRIES,\n\t\t\tretryDelay: DEFAULT_RETRY_DELAY,\n\t\t\t...config,\n\t\t}\n\n\t\tconst clientOptions: T_CassandraClientOptions = {\n\t\t\tcontactPoints: this.config.contactPoints,\n\t\t\tlocalDataCenter: this.config.localDataCenter,\n\t\t\tkeyspace: this.config.keyspace,\n\t\t\tprotocolOptions: {\n\t\t\t\tport: this.config.port,\n\t\t\t},\n\t\t}\n\n\t\tif (this.config.pooling) {\n\t\t\tclientOptions.pooling = this.config.pooling\n\t\t}\n\n\t\tthis.driver = new Cassandra.Client(clientOptions)\n\t}\n\n\tconfig: ClientConfig\n\tdriver: T_CassandraClient\n\tmapper: T_CassandraMapping.Mapper\n\tmodels: Map<string, Model<any>> = new Map()\n\n\tasync initialize(options: { sync?: boolean } = {}) {\n\t\tlet models: Model<any>[]\n\n\t\ttry {\n\t\t\tmodels = await loadModels(this.config.modelsPath)\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to load models: ${error.message}`)\n\t\t}\n\n\t\tmodels = models.filter((schema) => schema instanceof Model)\n\n\t\tthis.mapper = new Cassandra.mapping.Mapper(this.driver, {\n\t\t\tmodels: buildMapper(models),\n\t\t})\n\n\t\tfor (let model of models) {\n\t\t\tthis.models.set(\n\t\t\t\tmodel.name,\n\t\t\t\tmodel as Model<InferDocument<typeof model.schema>>,\n\t\t\t)\n\n\t\t\tif (options?.sync === true) {\n\t\t\t\tawait model._sync()\n\t\t\t}\n\t\t}\n\n\t\tglobalThis.__scylla_client = this\n\n\t\tconsole.log(\"Connecting to ScyllaDB\")\n\t\tawait this.connectWithRetry()\n\t\tconsole.log(\"ScyllaDB Connected\")\n\t}\n\n\tprivate async connectWithRetry(): Promise<void> {\n\t\tlet lastError: Error | null = null\n\n\t\tfor (let attempt = 1; attempt <= this.config.maxRetries!; attempt++) {\n\t\t\ttry {\n\t\t\t\tawait this.driver.connect()\n\t\t\t\treturn\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Connection attempt ${attempt} failed: ${error.message}`,\n\t\t\t\t)\n\n\t\t\t\tif (attempt < this.config.maxRetries!) {\n\t\t\t\t\tconsole.log(`Retrying in ${this.config.retryDelay}ms...`)\n\t\t\t\t\tawait this.delay(this.config.retryDelay!)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Failed to connect to ScyllaDB after ${this.config.maxRetries} attempts: ${lastError?.message}`,\n\t\t)\n\t}\n\n\tprivate delay(ms: number): Promise<void> {\n\t\treturn new Promise((resolve) => setTimeout(resolve, ms))\n\t}\n\n\tasync shutdown(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.driver.shutdown()\n\t\t\tconsole.log(\"ScyllaDB connection closed\")\n\n\t\t\tdelete globalThis.__scylla_client\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Error shutting down ScyllaDB connection:\", error)\n\t\t\tthrow error\n\t\t}\n\t}\n\n\tasync executeWithRetry<T>(\n\t\toperation: () => Promise<T>,\n\t\toperationName: string = \"operation\",\n\t): Promise<T> {\n\t\tlet lastError: Error | null = null\n\n\t\tfor (let attempt = 1; attempt <= this.config.maxRetries!; attempt++) {\n\t\t\ttry {\n\t\t\t\treturn await operation()\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error\n\n\t\t\t\t// check if error is retryable\n\t\t\t\tif (\n\t\t\t\t\tthis.isRetryableError(error) &&\n\t\t\t\t\tattempt < this.config.maxRetries!\n\t\t\t\t) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`Operation ${operationName} attempt ${attempt} failed: ${error.message}`,\n\t\t\t\t\t)\n\t\t\t\t\tconsole.log(`Retrying in ${this.config.retryDelay}ms...`)\n\n\t\t\t\t\tawait this.delay(this.config.retryDelay!)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\t// if not retryable or last attempt, throw\n\t\t\t\tthrow error\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Operation ${operationName} failed after ${this.config.maxRetries} attempts: ${lastError?.message}`,\n\t\t)\n\t}\n\n\tprivate isRetryableError(error: any): boolean {\n\t\t// retry on network errors, timeouts, and certain ScyllaDB errors\n\t\tconst retryableMessages = [\n\t\t\t\"timeout\",\n\t\t\t\"connection\",\n\t\t\t\"network\",\n\t\t\t\"unavailable\",\n\t\t\t\"overloaded\",\n\t\t\t\"no hosts available\",\n\t\t]\n\n\t\tconst errorMessage = error.message?.toLowerCase() || \"\"\n\n\t\treturn retryableMessages.some((msg) => errorMessage.includes(msg))\n\t}\n}\n\nexport default Client\n"],"mappings":";;;;;;AAiBA,MAAM,sBAAsB;AAC5B,MAAM,sBAAsB;AAC5B,MAAM,EAAE,uBAAuB,0BAA0B,oBACxD,QAAQ;AAET,IAAa,SAAb,MAAoB;CACnB,YAAY,SAAuB,EAAE,EAAE;AACtC,MAAI,WAAW,gBACd,OAAM,IAAI,MACT,sDACA;AAGF,OAAK,SAAS;GACb,YAAY,KAAK,QAAQ,QAAQ,KAAK,EAAE,KAAK;GAC7C,eACE,OAAO,iBAAiB,wBACtB,sBAAsB,MAAM,IAAI,GAChC,CAAC,YAAY;GACjB,iBACC,OAAO,mBACP,4BACA;GACD,UAAU,OAAO,YAAY,mBAAmB;GAChD,MAAM;GACN,YAAY;GACZ,YAAY;GACZ,GAAG;GACH;EAED,MAAM,gBAA0C;GAC/C,eAAe,KAAK,OAAO;GAC3B,iBAAiB,KAAK,OAAO;GAC7B,UAAU,KAAK,OAAO;G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B;AAC/B,MAAI;AACH,SAAM,KAAK,OAAO,UAAU;AAC5B,WAAQ,IAAI,6BAA6B;AAEzC,UAAO,WAAW;WACV,OAAO;AACf,WAAQ,MAAM,4CAA4C,MAAM;AAChE,SAAM;;;CAIR,MAAM,iBACL,WACA,gBAAwB,aACX;EACb,IAAI,YAA0B;AAE9B,OAAK,IAAI,UAAU,GAAG,WAAW,KAAK,OAAO,YAAa,UACzD,KAAI;AACH,UAAO,MAAM,WAAW;WAChB,OAAO;AACf,eAAY;AAGZ,OACC,KAAK,iBAAiB,MAAM,IAC5B,UAAU,KAAK,OAAO,YACrB;AACD,YAAQ,KACP,aAAa,cAAc,WAAW,QAAQ,WAAW,MAAM,UAC/D;AACD,YAAQ,IAAI,eAAe,KAAK,OAAO,WAAW,OAAO;AAEzD,UAAM,KAAK,MAAM,KAAK,OAAO,WAAY;AACzC;;AAID,SAAM;;AAIR,QAAM,IAAI,MACT,aAAa,cAAc,gBAAgB,KAAK,OAAO,WAAW,aAAa,WAAW,UAC1F;;CAGF,iBAAyB,OAAqB;EAE7C,MAAM,oBAAoB;GACzB;GACA;GACA;GACA;GACA;GACA;GACA;EAED,MAAM,eAAe,MAAM,SAAS,aAAa,IAAI;AAErD,SAAO,kBAAkB,MAAM,QAAQ,aAAa,SAAS,IAAI,CAAC"}
1
+ {"version":3,"file":"client.js","names":["loadModels","buildMapper"],"sources":["../src/client.ts"],"sourcesContent":["import type {\n\tClient as T_CassandraClient,\n\tClientOptions as T_CassandraClientOptions,\n\tmapping as T_CassandraMapping,\n} from \"cassandra-driver\"\nimport type { ClientConfig } from \"./types\"\n\n//@ts-ignore\nimport path from \"node:path\"\n//@ts-ignore\nimport Cassandra from \"cassandra-driver\"\nimport loadModels from \"./utils/loadModels\"\nimport buildMapper from \"./utils/buildMapper\"\n\nimport { Model } from \"./model\"\nimport { InferDocument } from \"./types\"\n\nconst DEFAULT_MAX_RETRIES = 3\nconst DEFAULT_RETRY_DELAY = 1000\nconst { SCYLLA_CONTACT_POINTS, SCYLLA_LOCAL_DATA_CENTER, SCYLLA_KEYSPACE } =\n\tprocess.env\n\nexport class Client {\n\tconstructor(config: ClientConfig = {}) {\n\t\tif (globalThis.__scylla_client) {\n\t\t\tthrow new Error(\n\t\t\t\t\"An instance of Scylla Client is already initialized\",\n\t\t\t)\n\t\t}\n\n\t\tthis.config = {\n\t\t\tmodelsPath: path.resolve(process.cwd(), \"db\"),\n\t\t\tcontactPoints:\n\t\t\t\t(config.contactPoints ?? SCYLLA_CONTACT_POINTS)\n\t\t\t\t\t? SCYLLA_CONTACT_POINTS.split(\",\")\n\t\t\t\t\t: [\"127.0.0.1\"],\n\t\t\tlocalDataCenter:\n\t\t\t\tconfig.localDataCenter ??\n\t\t\t\tSCYLLA_LOCAL_DATA_CENTER ??\n\t\t\t\t\"datacenter1\",\n\t\t\tkeyspace: config.keyspace ?? SCYLLA_KEYSPACE ?? \"default\",\n\t\t\tport: 9042,\n\t\t\tmaxRetries: DEFAULT_MAX_RETRIES,\n\t\t\tretryDelay: DEFAULT_RETRY_DELAY,\n\t\t\t...config,\n\t\t}\n\n\t\tconst clientOptions: T_CassandraClientOptions = {\n\t\t\tcontactPoints: this.config.contactPoints,\n\t\t\tlocalDataCenter: this.config.localDataCenter,\n\t\t\tkeyspace: this.config.keyspace,\n\t\t\tprotocolOptions: {\n\t\t\t\tport: this.config.port,\n\t\t\t},\n\t\t}\n\n\t\tif (this.config.pooling) {\n\t\t\tclientOptions.pooling = this.config.pooling\n\t\t}\n\n\t\tthis.driver = new Cassandra.Client(clientOptions)\n\t}\n\n\tconfig: ClientConfig\n\tdriver: T_CassandraClient\n\tmapper: T_CassandraMapping.Mapper\n\tmodels: Map<string, Model<any>> = new Map()\n\n\tmodel(name: string): Model<any> | undefined {\n\t\treturn this.models.get(name)\n\t}\n\n\tasync initialize(options: { sync?: boolean } = {}) {\n\t\tlet models: Model<any>[]\n\n\t\ttry {\n\t\t\tmodels = await loadModels(this.config.modelsPath)\n\t\t} catch (error) {\n\t\t\tthrow new Error(`Failed to load models: ${error.message}`)\n\t\t}\n\n\t\tmodels = models.filter((schema) => schema instanceof Model)\n\n\t\tthis.mapper = new Cassandra.mapping.Mapper(this.driver, {\n\t\t\tmodels: buildMapper(models),\n\t\t})\n\n\t\tfor (let model of models) {\n\t\t\tthis.models.set(\n\t\t\t\tmodel.name,\n\t\t\t\tmodel as Model<InferDocument<typeof model.schema>>,\n\t\t\t)\n\n\t\t\tif (options?.sync === true) {\n\t\t\t\tawait model._sync()\n\t\t\t}\n\t\t}\n\n\t\tglobalThis.__scylla_client = this\n\n\t\tconsole.log(\"Connecting to ScyllaDB\")\n\t\tawait this.connectWithRetry()\n\t\tconsole.log(\"ScyllaDB Connected\")\n\t}\n\n\tprivate async connectWithRetry(): Promise<void> {\n\t\tlet lastError: Error | null = null\n\n\t\tfor (let attempt = 1; attempt <= this.config.maxRetries!; attempt++) {\n\t\t\ttry {\n\t\t\t\tawait this.driver.connect()\n\t\t\t\treturn\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Connection attempt ${attempt} failed: ${error.message}`,\n\t\t\t\t)\n\n\t\t\t\tif (attempt < this.config.maxRetries!) {\n\t\t\t\t\tconsole.log(`Retrying in ${this.config.retryDelay}ms...`)\n\t\t\t\t\tawait this.delay(this.config.retryDelay!)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Failed to connect to ScyllaDB after ${this.config.maxRetries} attempts: ${lastError?.message}`,\n\t\t)\n\t}\n\n\tprivate delay(ms: number): Promise<void> {\n\t\treturn new Promise((resolve) => setTimeout(resolve, ms))\n\t}\n\n\tasync shutdown(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.driver.shutdown()\n\t\t\tconsole.log(\"ScyllaDB connection closed\")\n\n\t\t\tdelete globalThis.__scylla_client\n\t\t} catch (error) {\n\t\t\tconsole.error(\"Error shutting down ScyllaDB connection:\", error)\n\t\t\tthrow error\n\t\t}\n\t}\n\n\tasync executeWithRetry<T>(\n\t\toperation: () => Promise<T>,\n\t\toperationName: string = \"operation\",\n\t): Promise<T> {\n\t\tlet lastError: Error | null = null\n\n\t\tfor (let attempt = 1; attempt <= this.config.maxRetries!; attempt++) {\n\t\t\ttry {\n\t\t\t\treturn await operation()\n\t\t\t} catch (error) {\n\t\t\t\tlastError = error\n\n\t\t\t\t// check if error is retryable\n\t\t\t\tif (\n\t\t\t\t\tthis.isRetryableError(error) &&\n\t\t\t\t\tattempt < this.config.maxRetries!\n\t\t\t\t) {\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`Operation ${operationName} attempt ${attempt} failed: ${error.message}`,\n\t\t\t\t\t)\n\t\t\t\t\tconsole.log(`Retrying in ${this.config.retryDelay}ms...`)\n\n\t\t\t\t\tawait this.delay(this.config.retryDelay!)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\t// if not retryable or last attempt, throw\n\t\t\t\tthrow error\n\t\t\t}\n\t\t}\n\n\t\tthrow new Error(\n\t\t\t`Operation ${operationName} failed after ${this.config.maxRetries} attempts: ${lastError?.message}`,\n\t\t)\n\t}\n\n\tprivate isRetryableError(error: any): boolean {\n\t\t// retry on network errors, timeouts, and certain ScyllaDB errors\n\t\tconst retryableMessages = [\n\t\t\t\"timeout\",\n\t\t\t\"connection\",\n\t\t\t\"network\",\n\t\t\t\"unavailable\",\n\t\t\t\"overloaded\",\n\t\t\t\"no hosts available\",\n\t\t]\n\n\t\tconst errorMessage = error.message?.toLowerCase() || \"\"\n\n\t\treturn retryableMessages.some((msg) => errorMessage.includes(msg))\n\t}\n}\n\nexport default Client\n"],"mappings":";;;;;;AAiBA,MAAM,sBAAsB;AAC5B,MAAM,sBAAsB;AAC5B,MAAM,EAAE,uBAAuB,0BAA0B,oBACxD,QAAQ;AAET,IAAa,SAAb,MAAoB;CACnB,YAAY,SAAuB,EAAE,EAAE;AACtC,MAAI,WAAW,gBACd,OAAM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I,CAAC"}
package/model/index.d.ts CHANGED
@@ -13,6 +13,7 @@ declare class Model<TDoc = any> {
13
13
  get mapper(): mapping.ModelMapper;
14
14
  constructor(name: string, schema: Schema<any>);
15
15
  create: (data: Partial<TDoc>) => DocumentResult<TDoc>;
16
+ obj: (data: Partial<TDoc>) => DocumentResult<TDoc>;
16
17
  find: {
17
18
  (query: Query<TDoc>, options: QueryOptions & {
18
19
  raw: true;
package/model/index.js CHANGED
@@ -26,6 +26,7 @@ var Model = class {
26
26
  if (!this.schema.fields || typeof this.schema.fields !== "object") throw new Error(`[${this.name}] model has missing or invalid "fields"`);
27
27
  }
28
28
  create = (data) => this._wrap(data);
29
+ obj = (data) => this._wrap(data);
29
30
  find = findOP.bind(this);
30
31
  findOne = findOne_default.bind(this);
31
32
  update = update_default.bind(this);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["findOneOP","updateOP","deleteOP","countAllOP","tableExistsOP"],"sources":["../../src/model/index.ts"],"sourcesContent":["import Client from \"..\"\nimport { Result } from \"../result\"\n\nimport fillDefaults from \"../utils/fillDefaults\"\n\nimport { mapping } from \"cassandra-driver/lib/mapping\"\nimport type { DocumentResult, Query, QueryOptions } from \"../types\"\nimport type { Schema } from \"../schema\"\n\nimport findOneOP from \"../operations/findOne\"\nimport findOP from \"../operations/find\"\nimport updateOP from \"../operations/update\"\nimport deleteOP from \"../operations/delete\"\nimport countAllOP from \"../operations/countAll\"\n\nimport tableExistsOP from \"../operations/tableExists\"\nimport syncOP from \"../operations/sync\"\n\nexport class Model<TDoc = any> {\n\tname: string\n\tschema: Schema<any>\n\n\tget client(): Client {\n\t\treturn globalThis.__scylla_client\n\t}\n\n\tget mapper(): mapping.ModelMapper {\n\t\tif (!globalThis.__scylla_client?.mapper) {\n\t\t\tthrow new Error(\"No mapper available\")\n\t\t}\n\n\t\treturn globalThis.__scylla_client.mapper.forModel(this.name)\n\t}\n\n\tconstructor(name: string, schema: Schema<any>) {\n\t\tthis.name = name\n\t\tthis.schema = schema\n\n\t\tif (!Array.isArray(this.schema.keys)) {\n\t\t\tthrow new Error(`[${this.name}] model has missing \"keys\" array`)\n\t\t}\n\t\tif (!this.schema.table_name) {\n\t\t\tthrow new Error(`[${this.name}] model has missing \"table_name\"`)\n\t\t}\n\t\tif (!this.schema.fields || typeof this.schema.fields !== \"object\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[${this.name}] model has missing or invalid \"fields\"`,\n\t\t\t)\n\t\t}\n\t}\n\n\tcreate = (data: Partial<TDoc>) => this._wrap(data)\n\n\tfind: {\n\t\t(\n\t\t\tquery: Query<TDoc>,\n\t\t\toptions: QueryOptions & { raw: true },\n\t\t): Promise<TDoc[]>\n\t\t(\n\t\t\tquery?: Query<TDoc>,\n\t\t\toptions?: QueryOptions,\n\t\t): Promise<DocumentResult<TDoc>[]>\n\t} = findOP.bind(this)\n\n\tfindOne: {\n\t\t(\n\t\t\tquery: Query<TDoc>,\n\t\t\toptions: QueryOptions & { raw: true },\n\t\t): Promise<TDoc>\n\t\t(\n\t\t\tquery?: Query<TDoc>,\n\t\t\toptions?: QueryOptions,\n\t\t): Promise<DocumentResult<TDoc>>\n\t} = findOneOP.bind(this)\n\n\tupdate: (query: Query<TDoc>) => Promise<DocumentResult<TDoc>> =\n\t\tupdateOP.bind(this)\n\n\tdelete: (query: Query<TDoc>) => Promise<mapping.Result> =\n\t\tdeleteOP.bind(this)\n\n\tcountAll: () => Promise<number> = countAllOP.bind(this)\n\n\t_sync: typeof syncOP = syncOP.bind(this)\n\t_tableExists: typeof tableExistsOP = tableExistsOP.bind(this)\n\n\t_wrap(row: any): DocumentResult<TDoc> | null {\n\t\tif (!row) {\n\t\t\treturn null\n\t\t}\n\n\t\trow = fillDefaults(this.schema, row)\n\n\t\treturn new Result<TDoc>(row, this) as DocumentResult<TDoc>\n\t}\n}\n\nexport default Model\n"],"mappings":";;;;;;;;;;AAkBA,IAAa,QAAb,MAA+B;CAC9B;CACA;CAEA,IAAI,SAAiB;AACpB,SAAO,WAAW;;CAGnB,IAAI,SAA8B;AACjC,MAAI,CAAC,WAAW,iBAAiB,OAChC,OAAM,IAAI,MAAM,sBAAsB;AAGvC,SAAO,WAAW,gBAAgB,OAAO,SAAS,KAAK,KAAK;;CAG7D,YAAY,MAAc,QAAqB;AAC9C,OAAK,OAAO;AACZ,OAAK,SAAS;AAEd,MAAI,CAAC,MAAM,QAAQ,KAAK,OAAO,KAAK,CACnC,OAAM,IAAI,MAAM,IAAI,KAAK,KAAK,kCAAkC;AAEjE,MAAI,CAAC,KAAK,OAAO,WAChB,OAAM,IAAI,MAAM,IAAI,KAAK,KAAK,kCAAkC;AAEjE,MAAI,CAAC,KAAK,OAAO,UAAU,OAAO,KAAK,OAAO,WAAW,SACxD,OAAM,IAAI,MACT,IAAI,KAAK,KAAK,yCACd;;CAIH,UAAU,SAAwB,KAAK,MAAM,KAAK;CAElD,OASI,OAAO,KAAK,KAAK;CAErB,UASIA,gBAAU,KAAK,KAAK;CAExB,SACCC,eAAS,KAAK,KAAK;CAEpB,SACCC,eAAS,KAAK,KAAK;CAEpB,WAAkCC,iBAAW,KAAK,KAAK;CAEvD,QAAuB,OAAO,KAAK,KAAK;CACxC,eAAqCC,oBAAc,KAAK,KAAK;CAE7D,MAAM,KAAuC;AAC5C,MAAI,CAAC,IACJ,QAAO;AAGR,QAAM,aAAa,KAAK,QAAQ,IAAI;AAEpC,SAAO,IAAI,OAAa,KAAK,KAAK"}
1
+ {"version":3,"file":"index.js","names":["findOneOP","updateOP","deleteOP","countAllOP","tableExistsOP"],"sources":["../../src/model/index.ts"],"sourcesContent":["import Client from \"..\"\nimport { Result } from \"../result\"\n\nimport fillDefaults from \"../utils/fillDefaults\"\n\nimport { mapping } from \"cassandra-driver/lib/mapping\"\nimport type { DocumentResult, Query, QueryOptions } from \"../types\"\nimport type { Schema } from \"../schema\"\n\nimport findOneOP from \"../operations/findOne\"\nimport findOP from \"../operations/find\"\nimport updateOP from \"../operations/update\"\nimport deleteOP from \"../operations/delete\"\nimport countAllOP from \"../operations/countAll\"\n\nimport tableExistsOP from \"../operations/tableExists\"\nimport syncOP from \"../operations/sync\"\n\nexport class Model<TDoc = any> {\n\tname: string\n\tschema: Schema<any>\n\n\tget client(): Client {\n\t\treturn globalThis.__scylla_client\n\t}\n\n\tget mapper(): mapping.ModelMapper {\n\t\tif (!globalThis.__scylla_client?.mapper) {\n\t\t\tthrow new Error(\"No mapper available\")\n\t\t}\n\n\t\treturn globalThis.__scylla_client.mapper.forModel(this.name)\n\t}\n\n\tconstructor(name: string, schema: Schema<any>) {\n\t\tthis.name = name\n\t\tthis.schema = schema\n\n\t\tif (!Array.isArray(this.schema.keys)) {\n\t\t\tthrow new Error(`[${this.name}] model has missing \"keys\" array`)\n\t\t}\n\t\tif (!this.schema.table_name) {\n\t\t\tthrow new Error(`[${this.name}] model has missing \"table_name\"`)\n\t\t}\n\t\tif (!this.schema.fields || typeof this.schema.fields !== \"object\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[${this.name}] model has missing or invalid \"fields\"`,\n\t\t\t)\n\t\t}\n\t}\n\n\tcreate = (data: Partial<TDoc>) => this._wrap(data)\n\tobj = (data: Partial<TDoc>) => this._wrap(data)\n\n\tfind: {\n\t\t(\n\t\t\tquery: Query<TDoc>,\n\t\t\toptions: QueryOptions & { raw: true },\n\t\t): Promise<TDoc[]>\n\t\t(\n\t\t\tquery?: Query<TDoc>,\n\t\t\toptions?: QueryOptions,\n\t\t): Promise<DocumentResult<TDoc>[]>\n\t} = findOP.bind(this)\n\n\tfindOne: {\n\t\t(\n\t\t\tquery: Query<TDoc>,\n\t\t\toptions: QueryOptions & { raw: true },\n\t\t): Promise<TDoc>\n\t\t(\n\t\t\tquery?: Query<TDoc>,\n\t\t\toptions?: QueryOptions,\n\t\t): Promise<DocumentResult<TDoc>>\n\t} = findOneOP.bind(this)\n\n\tupdate: (query: Query<TDoc>) => Promise<DocumentResult<TDoc>> =\n\t\tupdateOP.bind(this)\n\n\tdelete: (query: Query<TDoc>) => Promise<mapping.Result> =\n\t\tdeleteOP.bind(this)\n\n\tcountAll: () => Promise<number> = countAllOP.bind(this)\n\n\t_sync: typeof syncOP = syncOP.bind(this)\n\t_tableExists: typeof tableExistsOP = tableExistsOP.bind(this)\n\n\t_wrap(row: any): DocumentResult<TDoc> | null {\n\t\tif (!row) {\n\t\t\treturn null\n\t\t}\n\n\t\trow = fillDefaults(this.schema, row)\n\n\t\treturn new Result<TDoc>(row, this) as DocumentResult<TDoc>\n\t}\n}\n\nexport default Model\n"],"mappings":";;;;;;;;;;AAkBA,IAAa,QAAb,MAA+B;CAC9B;CACA;CAEA,IAAI,SAAiB;AACpB,SAAO,WAAW;;CAGnB,IAAI,SAA8B;AACjC,MAAI,CAAC,WAAW,iBAAiB,OAChC,OAAM,IAAI,MAAM,sBAAsB;AAGvC,SAAO,WAAW,gBAAgB,OAAO,SAAS,KAAK,KAAK;;CAG7D,YAAY,MAAc,QAAqB;AAC9C,OAAK,OAAO;AACZ,OAAK,SAAS;AAEd,MAAI,CAAC,MAAM,QAAQ,KAAK,OAAO,KAAK,CACnC,OAAM,IAAI,MAAM,IAAI,KAAK,KAAK,kCAAkC;AAEjE,MAAI,CAAC,KAAK,OAAO,WAChB,OAAM,IAAI,MAAM,IAAI,KAAK,KAAK,kCAAkC;AAEjE,MAAI,CAAC,KAAK,OAAO,UAAU,OAAO,KAAK,OAAO,WAAW,SACxD,OAAM,IAAI,MACT,IAAI,KAAK,KAAK,yCACd;;CAIH,UAAU,SAAwB,KAAK,MAAM,KAAK;CAClD,OAAO,SAAwB,KAAK,MAAM,KAAK;CAE/C,OASI,OAAO,KAAK,KAAK;CAErB,UASIA,gBAAU,KAAK,KAAK;CAExB,SACCC,eAAS,KAAK,KAAK;CAEpB,SACCC,eAAS,KAAK,KAAK;CAEpB,WAAkCC,iBAAW,KAAK,KAAK;CAEvD,QAAuB,OAAO,KAAK,KAAK;CACxC,eAAqCC,oBAAc,KAAK,KAAK;CAE7D,MAAM,KAAuC;AAC5C,MAAI,CAAC,IACJ,QAAO;AAGR,QAAM,aAAa,KAAK,QAAQ,IAAI;AAEpC,SAAO,IAAI,OAAa,KAAK,KAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ragestudio/scylla-odm",
3
- "version": "0.10.3",
3
+ "version": "0.12.0",
4
4
  "description": "An ODM for ScyllaDB",
5
5
  "license": "MIT",
6
6
  "author": "RageStudio",