couchset 0.0.16 → 0.0.18
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/automate/model/index.js +1 -1
- package/dist/automate/model/index.js.map +1 -1
- package/dist/automate/morpheus/index.js +1 -1
- package/dist/automate/writer/index.js +1 -1
- package/dist/connection.js +1 -1
- package/dist/index.js +1 -1
- package/dist/model/index.js +17 -17
- package/dist/model/index.js.map +1 -1
- package/dist/pagination/pagination.js +1 -1
- package/dist/query/interface/query.types.d.ts +22 -22
- package/dist/query/query.cluster.js +1 -1
- package/dist/search/customQuery.js +1 -1
- package/dist/shared/common.model.js +1 -1
- package/dist/utils/utils.schema.d.ts +1 -1
- package/package.json +4 -4
|
@@ -34,7 +34,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
34
34
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
35
35
|
function step(op) {
|
|
36
36
|
if (f) throw new TypeError("Generator is already executing.");
|
|
37
|
-
while (_) try {
|
|
37
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
38
38
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
39
39
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
40
40
|
switch (op[0]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/automate/model/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,+DAAyC;AACzC,yDAAmC;AACnC,wEAA4C;AAC5C,iCAAgC;AAChC,6CAUsB;AAGtB,qCAAyC;AAEzC,8CAAsC;AACtC,uCAAmD;AAEnD,mCAAwC;AAmDxC;;;;GAIG;AACI,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CAAC,CAAA;6CAoBhD;QAID;YAFC,IAAA,uBAAQ,EAAC,cAAM,OAAA,YAAY,EAAZ,CAAY,CAAC;YAC5B,IAAA,4BAAa,EAAC,uBAAuB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,cAAc,CAAC;YAErE,WAAA,IAAA,kBAAG,EAAC,IAAI,EAAE,cAAM,OAAA,MAAM,EAAN,CAAM,EAAE,EAAC,QAAQ,EAAE,KAAK,EAAC,CAAC,CAAA;YAC1C,WAAA,IAAA,kBAAG,EAAC,OAAO,EAAE,cAAM,OAAA,MAAM,EAAN,CAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;6CAsBhD;QAID;YAFC,IAAA,uBAAQ,EAAC,cAAM,OAAA,YAAY,EAAZ,CAAY,CAAC;YAC5B,IAAA,4BAAa,EAAC,yBAAyB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,cAAc,CAAC;YAGvE,WAAA,IAAA,kBAAG,EAAC,MAAM,EAAE,cAAM,OAAA,cAAc,EAAd,CAAc,CAAC,CAAA;6CA4BrC;QAzJC,aAAa;YADlB,IAAA,uBAAQ,GAAE;WACL,aAAa,CA0JlB;QAAD,oBAAC;KAAA,AA1JD,IA0JC;IAED,MAAM;IACN,0CAA0C;IAC1C,IAAM,MAAM,GAAG,IAAA,uBAAc,EAAC;QAC1B,IAAI,MAAA;QACJ,MAAM,EAAE,SAAS;KACpB,CAAC,CAAC;IAEH,OAAO;QACH,OAAO,EAAE,YAAkC;QAC3C,UAAU,EAAE,eAAe;QAC3B,QAAQ,EAAE,aAAa;QACvB,SAAS,WAAA;QACT,MAAM,QAAA;KACT,CAAC;AACN,CAAC,CAAC;AAxOW,QAAA,sBAAsB,0BAwOjC","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport camelCase from 'lodash/camelCase';\nimport pickBy from 'lodash/pickBy';\nimport GraphQLJSON from 'graphql-type-json';\nimport {identity} from 'lodash';\nimport {\n Field,\n Mutation,\n ObjectType,\n UseMiddleware,\n Arg,\n ClassType,\n Resolver,\n Query,\n InputType,\n} from 'type-graphql';\nimport {DocumentNode} from 'graphql';\n\nimport {awaitTo, log} from '../../utils';\nimport {Model} from '../../model';\nimport {isAuth} from '../middlewares';\nimport {createUpdate, ResType} from '../../shared';\n\nimport {generateClient} from './client';\n\ninterface PaginationResults {\n items: any[];\n hasNext: boolean;\n params: any;\n}\n\nexport interface AutomaticModelOptions extends AutomaticMethodOptions {\n model: Model;\n}\n\nexport interface AutomaticMethodOptions {\n authMiddleware?: any; // authentication middleware\n\n // Query\n pagination?: {\n public?: boolean;\n method?: (params: any) => Promise<PaginationResults>;\n };\n\n getById?: {\n public?: boolean;\n matchOwner?: boolean;\n method?: <T>(params: any) => Promise<T & any>;\n };\n\n // Mutations\n deleteById?: {\n public?: boolean; // NEVER SET IN PROD\n method?: (args: any) => Promise<ResType>;\n matchOwner?: boolean;\n };\n\n createUpdate?: {\n public?: boolean; // NEVER SET IN PROD\n method?: <T>(args: T) => Promise<ResType>;\n };\n\n // TODO in the future\n // fragmentMapping\n}\n\nexport interface AutomaticOutput {\n resType: ResType;\n pagination: ClassType;\n resolver: ClassType;\n modelKeys: string[];\n client: Record<string, DocumentNode>;\n}\n\n/**\n *\n * @param c\n * @returns\n */\nexport const automateImplementation = <T>(\n ClassModelType: T & ClassType,\n options: AutomaticModelOptions\n): AutomaticOutput => {\n // createUpdate\n const createUpdateOptions = options?.createUpdate;\n const createUpdateOptionsPublic = options?.createUpdate?.public;\n\n // deleteById\n const deleteByIdOptions = options?.deleteById;\n const deleteByIdOptionsPublic = options?.deleteById?.public;\n\n // getById\n const getByIdOptions = options?.getById;\n const getByIdOptionsPublic = options?.getById?.public;\n\n // pagination\n const paginationOptions = options?.pagination;\n const paginationOptionsPublic = options?.pagination?.public;\n\n type ClassModelTYPE = typeof ClassModelType;\n\n const ClassModel = options.model;\n const name = (ClassModelType as any).name;\n const _type = ClassModel.collectionName;\n const nameCamel = camelCase(name);\n // const nameSNAKE_CASE = toUpper(snakeCase(name));\n const modelKeys: string[] = Object.getOwnPropertyNames(new ClassModelType());\n\n const authMiddleware = options.authMiddleware || isAuth;\n\n const blankMiddleware = [];\n\n @ObjectType(`${nameCamel}ResType`)\n class ClassResType {\n @Field(() => Boolean)\n success: boolean;\n\n @Field(() => String, {nullable: true})\n message?: string;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n @Field((type) => GraphQLJSON, {nullable: true})\n data?: any;\n }\n\n @InputType(`${nameCamel}PaginationInput`)\n @ObjectType(`${nameCamel}Pagination`)\n class PaginationClass {\n @Field(() => [ClassModelType], {nullable: true})\n items: [typeof ClassModelType] = [ClassModelType];\n\n @Field(() => Boolean, {nullable: true})\n hasNext?: boolean = false;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n @Field((type) => GraphQLJSON, {nullable: true})\n params?: any = {};\n }\n // return Pagination;\n\n @Resolver()\n class ResolverClass {\n @Query(() => PaginationClass)\n @UseMiddleware(paginationOptionsPublic ? blankMiddleware : authMiddleware)\n async [`${nameCamel}Pagination`](\n @Arg('filter', () => String, {nullable: true}) filter?: string,\n @Arg('sort', () => String, {nullable: true}) sort?: string,\n @Arg('before', () => Date, {nullable: true}) before?: Date,\n @Arg('after', () => Date, {nullable: true}) after?: Date,\n @Arg('limit', () => Number, {nullable: true}) limitArg?: number\n ): Promise<{\n items: ClassModelTYPE[];\n hasNext: boolean;\n params: any;\n }> {\n const limit = limitArg || 10;\n\n const copyParams = pickBy(\n {\n filter,\n sort,\n before,\n after,\n limit,\n },\n identity\n );\n\n log(`${nameCamel}Pagination -->`, copyParams);\n\n try {\n // Apply it from the methods\n if (paginationOptions && paginationOptions.method) {\n return await paginationOptions.method(copyParams);\n }\n\n const bucket = ClassModel.getBucketName();\n\n const query = `\n SELECT ${modelKeys.join(',')}\n FROM \\`${bucket}\\` ${nameCamel}\n WHERE ${nameCamel}._type = \"${_type}\"\n LIMIT ${limit};\n `;\n\n const [errorFetching, data = []] = await awaitTo(\n ClassModel.customQuery<any>({\n limit,\n query,\n params: copyParams,\n })\n );\n\n if (errorFetching) {\n throw errorFetching;\n }\n\n const [rows = [], options = {hasNext: false, params: copyParams}] = data;\n\n const dataToSend = rows.map((d) => ClassModel.parse(d));\n\n return {items: dataToSend, ...options};\n } catch (error) {\n log(`error paginating ${nameCamel}`, error);\n return {items: [], hasNext: false, params: copyParams};\n }\n }\n\n @Query(() => ClassModelType)\n @UseMiddleware(getByIdOptionsPublic ? blankMiddleware : authMiddleware)\n async [`${nameCamel}Get`](\n @Arg('id', () => String, {nullable: false}) id: string,\n @Arg('owner', () => String, {nullable: true}) owner?: string\n ): Promise<typeof ClassModelType> {\n try {\n log(`${nameCamel}Get -->`, {id, owner});\n // Apply it from the methods\n if (getByIdOptions && getByIdOptions.method) {\n return await getByIdOptions.method({id, owner});\n }\n\n // TODO check if we own this payment method\n const foundDocument = await ClassModel.findById(id);\n if (!foundDocument) {\n throw new Error(`${nameCamel} not found`);\n }\n\n return foundDocument;\n } catch (error) {\n log(`error finding ${nameCamel}`, error);\n return null;\n }\n }\n\n @Mutation(() => ClassResType)\n @UseMiddleware(deleteByIdOptionsPublic ? blankMiddleware : authMiddleware)\n async [`${nameCamel}Delete`](\n @Arg('id', () => String, {nullable: false}) id: string,\n @Arg('owner', () => String, {nullable: true}) owner?: string\n ): Promise<ResType> {\n log(`${nameCamel}Delete -->`, {id, owner});\n try {\n // Apply it from the methods\n if (deleteByIdOptions && deleteByIdOptions.method) {\n return await deleteByIdOptions.method({id, owner});\n }\n\n // TODO check if we own this payment method\n const deleted = await ClassModel.delete(id);\n if (!deleted) {\n throw new Error(`${nameCamel} not deleted`);\n }\n\n return {\n success: true,\n };\n } catch (error) {\n log(`error deleting ${nameCamel}`, error);\n return {success: false, message: error && error.message};\n }\n }\n\n @Mutation(() => ClassResType)\n @UseMiddleware(createUpdateOptionsPublic ? blankMiddleware : authMiddleware)\n async [`${nameCamel}Create`](\n // @ts-ignore\n @Arg('args', () => ClassModelType) args: ClassModelType\n ): Promise<ResType> {\n log(`${nameCamel}Create -->`, args);\n\n try {\n // Apply it from the methods\n if (createUpdateOptions && createUpdateOptions.method) {\n return await createUpdateOptions.method(args);\n }\n\n // If updating\n const createdOrUpdate = await createUpdate({\n model: ClassModel,\n data: {\n ...args,\n },\n ...args, // id and owner if it exists\n });\n\n if (createdOrUpdate) {\n return {success: true, data: createdOrUpdate};\n }\n\n throw new Error(`error creating ${nameCamel} method `);\n } catch (err) {\n console.error(err && err.message, err);\n return {success: false, message: err && err.message};\n }\n }\n }\n\n // GQL\n // { FRAGMENT, GET, DELETE, CREATE, PAGE }\n const client = generateClient({\n name,\n fields: modelKeys,\n });\n\n return {\n resType: ClassResType as unknown as ResType,\n pagination: PaginationClass,\n resolver: ResolverClass,\n modelKeys,\n client,\n };\n};\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/automate/model/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,+DAAyC;AACzC,yDAAmC;AACnC,wEAA4C;AAC5C,iCAAgC;AAChC,6CAUsB;AAGtB,qCAAyC;AAEzC,8CAAsC;AACtC,uCAAmD;AAEnD,mCAAwC;AAmDxC;;;;GAIG;AACI,IAAM,sBAAsB,GAAG,UAClC,cAA6B,EAC7B,OAA8B;;IAE9B,eAAe;IACf,IAAM,mBAAmB,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAC;IAClD,IAAM,yBAAyB,GAAG,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,0CAAE,MAAM,CAAC;IAEhE,aAAa;IACb,IAAM,iBAAiB,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAC;IAC9C,IAAM,uBAAuB,GAAG,M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AE,cAAM,OAAA,MAAM,EAAN,CAAM,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;6CAsBhD;QAIK;YAFL,IAAA,uBAAQ,EAAC,cAAM,OAAA,YAAY,EAAZ,CAAY,CAAC;YAC5B,IAAA,4BAAa,EAAC,yBAAyB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,cAAc,CAAC;YAGvE,WAAA,IAAA,kBAAG,EAAC,MAAM,EAAE,cAAM,OAAA,cAAc,EAAd,CAAc,CAAC,CAAA;6CA4BrC;QAzJC,aAAa;YADlB,IAAA,uBAAQ,GAAE;WACL,aAAa,CA0JlB;QAAD,oBAAC;KAAA,AA1JD,IA0JC;IAED,MAAM;IACN,0CAA0C;IAC1C,IAAM,MAAM,GAAG,IAAA,uBAAc,EAAC;QAC1B,IAAI,MAAA;QACJ,MAAM,EAAE,SAAS;KACpB,CAAC,CAAC;IAEH,OAAO;QACH,OAAO,EAAE,YAAkC;QAC3C,UAAU,EAAE,eAAe;QAC3B,QAAQ,EAAE,aAAa;QACvB,SAAS,WAAA;QACT,MAAM,QAAA;KACT,CAAC;AACN,CAAC,CAAC;AAxOW,QAAA,sBAAsB,0BAwOjC","sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport camelCase from 'lodash/camelCase';\nimport pickBy from 'lodash/pickBy';\nimport GraphQLJSON from 'graphql-type-json';\nimport {identity} from 'lodash';\nimport {\n Field,\n Mutation,\n ObjectType,\n UseMiddleware,\n Arg,\n ClassType,\n Resolver,\n Query,\n InputType,\n} from 'type-graphql';\nimport {DocumentNode} from 'graphql';\n\nimport {awaitTo, log} from '../../utils';\nimport {Model} from '../../model';\nimport {isAuth} from '../middlewares';\nimport {createUpdate, ResType} from '../../shared';\n\nimport {generateClient} from './client';\n\ninterface PaginationResults {\n items: any[];\n hasNext: boolean;\n params: any;\n}\n\nexport interface AutomaticModelOptions extends AutomaticMethodOptions {\n model: Model;\n}\n\nexport interface AutomaticMethodOptions {\n authMiddleware?: any; // authentication middleware\n\n // Query\n pagination?: {\n public?: boolean;\n method?: (params: any) => Promise<PaginationResults>;\n };\n\n getById?: {\n public?: boolean;\n matchOwner?: boolean;\n method?: <T>(params: any) => Promise<T & any>;\n };\n\n // Mutations\n deleteById?: {\n public?: boolean; // NEVER SET IN PROD\n method?: (args: any) => Promise<ResType>;\n matchOwner?: boolean;\n };\n\n createUpdate?: {\n public?: boolean; // NEVER SET IN PROD\n method?: <T>(args: T) => Promise<ResType>;\n };\n\n // TODO in the future\n // fragmentMapping\n}\n\nexport interface AutomaticOutput {\n resType: ResType;\n pagination: ClassType;\n resolver: ClassType;\n modelKeys: string[];\n client: Record<string, DocumentNode>;\n}\n\n/**\n *\n * @param c\n * @returns\n */\nexport const automateImplementation = <T>(\n ClassModelType: T & ClassType,\n options: AutomaticModelOptions\n): AutomaticOutput => {\n // createUpdate\n const createUpdateOptions = options?.createUpdate;\n const createUpdateOptionsPublic = options?.createUpdate?.public;\n\n // deleteById\n const deleteByIdOptions = options?.deleteById;\n const deleteByIdOptionsPublic = options?.deleteById?.public;\n\n // getById\n const getByIdOptions = options?.getById;\n const getByIdOptionsPublic = options?.getById?.public;\n\n // pagination\n const paginationOptions = options?.pagination;\n const paginationOptionsPublic = options?.pagination?.public;\n\n type ClassModelTYPE = typeof ClassModelType;\n\n const ClassModel = options.model;\n const name = (ClassModelType as any).name;\n const _type = ClassModel.collectionName;\n const nameCamel = camelCase(name);\n // const nameSNAKE_CASE = toUpper(snakeCase(name));\n const modelKeys: string[] = Object.getOwnPropertyNames(new ClassModelType());\n\n const authMiddleware = options.authMiddleware || isAuth;\n\n const blankMiddleware = [];\n\n @ObjectType(`${nameCamel}ResType`)\n class ClassResType {\n @Field(() => Boolean)\n success: boolean;\n\n @Field(() => String, {nullable: true})\n message?: string;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n @Field((type) => GraphQLJSON, {nullable: true})\n data?: any;\n }\n\n @InputType(`${nameCamel}PaginationInput`)\n @ObjectType(`${nameCamel}Pagination`)\n class PaginationClass {\n @Field(() => [ClassModelType], {nullable: true})\n items: [typeof ClassModelType] = [ClassModelType];\n\n @Field(() => Boolean, {nullable: true})\n hasNext?: boolean = false;\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n @Field((type) => GraphQLJSON, {nullable: true})\n params?: any = {};\n }\n // return Pagination;\n\n @Resolver()\n class ResolverClass {\n @Query(() => PaginationClass)\n @UseMiddleware(paginationOptionsPublic ? blankMiddleware : authMiddleware)\n async [`${nameCamel}Pagination`](\n @Arg('filter', () => String, {nullable: true}) filter?: string,\n @Arg('sort', () => String, {nullable: true}) sort?: string,\n @Arg('before', () => Date, {nullable: true}) before?: Date,\n @Arg('after', () => Date, {nullable: true}) after?: Date,\n @Arg('limit', () => Number, {nullable: true}) limitArg?: number\n ): Promise<{\n items: ClassModelTYPE[];\n hasNext: boolean;\n params: any;\n }> {\n const limit = limitArg || 10;\n\n const copyParams = pickBy(\n {\n filter,\n sort,\n before,\n after,\n limit,\n },\n identity\n );\n\n log(`${nameCamel}Pagination -->`, copyParams);\n\n try {\n // Apply it from the methods\n if (paginationOptions && paginationOptions.method) {\n return await paginationOptions.method(copyParams);\n }\n\n const bucket = ClassModel.getBucketName();\n\n const query = `\n SELECT ${modelKeys.join(',')}\n FROM \\`${bucket}\\` ${nameCamel}\n WHERE ${nameCamel}._type = \"${_type}\"\n LIMIT ${limit};\n `;\n\n const [errorFetching, data = []] = await awaitTo(\n ClassModel.customQuery<any>({\n limit,\n query,\n params: copyParams,\n })\n );\n\n if (errorFetching) {\n throw errorFetching;\n }\n\n const [rows = [], options = {hasNext: false, params: copyParams}] = data;\n\n const dataToSend = rows.map((d) => ClassModel.parse(d));\n\n return {items: dataToSend, ...options};\n } catch (error) {\n log(`error paginating ${nameCamel}`, error);\n return {items: [], hasNext: false, params: copyParams};\n }\n }\n\n @Query(() => ClassModelType)\n @UseMiddleware(getByIdOptionsPublic ? blankMiddleware : authMiddleware)\n async [`${nameCamel}Get`](\n @Arg('id', () => String, {nullable: false}) id: string,\n @Arg('owner', () => String, {nullable: true}) owner?: string\n ): Promise<typeof ClassModelType> {\n try {\n log(`${nameCamel}Get -->`, {id, owner});\n // Apply it from the methods\n if (getByIdOptions && getByIdOptions.method) {\n return await getByIdOptions.method({id, owner});\n }\n\n // TODO check if we own this payment method\n const foundDocument = await ClassModel.findById(id);\n if (!foundDocument) {\n throw new Error(`${nameCamel} not found`);\n }\n\n return foundDocument;\n } catch (error) {\n log(`error finding ${nameCamel}`, error);\n return null;\n }\n }\n\n @Mutation(() => ClassResType)\n @UseMiddleware(deleteByIdOptionsPublic ? blankMiddleware : authMiddleware)\n async [`${nameCamel}Delete`](\n @Arg('id', () => String, {nullable: false}) id: string,\n @Arg('owner', () => String, {nullable: true}) owner?: string\n ): Promise<ResType> {\n log(`${nameCamel}Delete -->`, {id, owner});\n try {\n // Apply it from the methods\n if (deleteByIdOptions && deleteByIdOptions.method) {\n return await deleteByIdOptions.method({id, owner});\n }\n\n // TODO check if we own this payment method\n const deleted = await ClassModel.delete(id);\n if (!deleted) {\n throw new Error(`${nameCamel} not deleted`);\n }\n\n return {\n success: true,\n };\n } catch (error) {\n log(`error deleting ${nameCamel}`, error);\n return {success: false, message: error && error.message};\n }\n }\n\n @Mutation(() => ClassResType)\n @UseMiddleware(createUpdateOptionsPublic ? blankMiddleware : authMiddleware)\n async [`${nameCamel}Create`](\n // @ts-ignore\n @Arg('args', () => ClassModelType) args: ClassModelType\n ): Promise<ResType> {\n log(`${nameCamel}Create -->`, args);\n\n try {\n // Apply it from the methods\n if (createUpdateOptions && createUpdateOptions.method) {\n return await createUpdateOptions.method(args);\n }\n\n // If updating\n const createdOrUpdate = await createUpdate({\n model: ClassModel,\n data: {\n ...args,\n },\n ...args, // id and owner if it exists\n });\n\n if (createdOrUpdate) {\n return {success: true, data: createdOrUpdate};\n }\n\n throw new Error(`error creating ${nameCamel} method `);\n } catch (err) {\n console.error(err && err.message, err);\n return {success: false, message: err && err.message};\n }\n }\n }\n\n // GQL\n // { FRAGMENT, GET, DELETE, CREATE, PAGE }\n const client = generateClient({\n name,\n fields: modelKeys,\n });\n\n return {\n resType: ClassResType as unknown as ResType,\n pagination: PaginationClass,\n resolver: ResolverClass,\n modelKeys,\n client,\n };\n};\n"]}
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
package/dist/connection.js
CHANGED
|
@@ -37,7 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
38
38
|
function step(op) {
|
|
39
39
|
if (f) throw new TypeError("Generator is already executing.");
|
|
40
|
-
while (_) try {
|
|
40
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
41
41
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
42
42
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
43
43
|
switch (op[0]) {
|
package/dist/index.js
CHANGED
|
@@ -28,7 +28,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
28
28
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
29
29
|
function step(op) {
|
|
30
30
|
if (f) throw new TypeError("Generator is already executing.");
|
|
31
|
-
while (_) try {
|
|
31
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
32
32
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
33
33
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
34
34
|
switch (op[0]) {
|
package/dist/model/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
25
25
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
26
|
function step(op) {
|
|
27
27
|
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
29
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
30
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
31
|
switch (op[0]) {
|
|
@@ -181,25 +181,25 @@ var Model = /** @class */ (function () {
|
|
|
181
181
|
*/
|
|
182
182
|
Model.prototype.updateById = function (id, data, opt) {
|
|
183
183
|
return __awaiter(this, void 0, void 0, function () {
|
|
184
|
-
var _a, silent, options, updatedDocument, error_3;
|
|
185
|
-
return __generator(this, function (
|
|
186
|
-
switch (
|
|
184
|
+
var _a, _b, silent, options, updatedDocument, error_3;
|
|
185
|
+
return __generator(this, function (_c) {
|
|
186
|
+
switch (_c.label) {
|
|
187
187
|
case 0:
|
|
188
188
|
this.fresh();
|
|
189
|
-
_a = opt.silent, silent =
|
|
189
|
+
_a = opt || {}, _b = _a.silent, silent = _b === void 0 ? false : _b, options = __rest(_a, ["silent"]);
|
|
190
190
|
updatedDocument = __assign(__assign({}, data), { id: id, _type: this.collectionName, _scope: this.scope });
|
|
191
191
|
if (!silent) {
|
|
192
192
|
updatedDocument.updatedAt = new Date();
|
|
193
193
|
}
|
|
194
|
-
|
|
194
|
+
_c.label = 1;
|
|
195
195
|
case 1:
|
|
196
|
-
|
|
196
|
+
_c.trys.push([1, 3, , 4]);
|
|
197
197
|
return [4 /*yield*/, this.collection.replace(id, updatedDocument, options)];
|
|
198
198
|
case 2:
|
|
199
|
-
|
|
199
|
+
_c.sent();
|
|
200
200
|
return [2 /*return*/, (0, utils_1.parseSchema)(this.schema, updatedDocument)];
|
|
201
201
|
case 3:
|
|
202
|
-
error_3 =
|
|
202
|
+
error_3 = _c.sent();
|
|
203
203
|
throw error_3;
|
|
204
204
|
case 4: return [2 /*return*/];
|
|
205
205
|
}
|
|
@@ -211,29 +211,29 @@ var Model = /** @class */ (function () {
|
|
|
211
211
|
*/
|
|
212
212
|
Model.prototype.save = function (data, opt) {
|
|
213
213
|
return __awaiter(this, void 0, void 0, function () {
|
|
214
|
-
var id, _a, silent, options, updatedDocument, error_4;
|
|
215
|
-
return __generator(this, function (
|
|
216
|
-
switch (
|
|
214
|
+
var id, _a, _b, silent, options, updatedDocument, error_4;
|
|
215
|
+
return __generator(this, function (_c) {
|
|
216
|
+
switch (_c.label) {
|
|
217
217
|
case 0:
|
|
218
218
|
this.fresh();
|
|
219
219
|
id = data && data.id;
|
|
220
|
-
_a = opt.silent, silent =
|
|
220
|
+
_a = opt || {}, _b = _a.silent, silent = _b === void 0 ? false : _b, options = __rest(_a, ["silent"]);
|
|
221
221
|
updatedDocument = __assign(__assign({}, data), { id: id, _type: this.collectionName, _scope: this.scope });
|
|
222
222
|
if (!silent) {
|
|
223
223
|
updatedDocument.updatedAt = new Date();
|
|
224
224
|
}
|
|
225
|
-
|
|
225
|
+
_c.label = 1;
|
|
226
226
|
case 1:
|
|
227
|
-
|
|
227
|
+
_c.trys.push([1, 3, , 4]);
|
|
228
228
|
if (!id) {
|
|
229
229
|
throw new Error('document must have id');
|
|
230
230
|
}
|
|
231
231
|
return [4 /*yield*/, this.collection.replace(id, updatedDocument, options)];
|
|
232
232
|
case 2:
|
|
233
|
-
|
|
233
|
+
_c.sent();
|
|
234
234
|
return [2 /*return*/, (0, utils_1.parseSchema)(this.schema, updatedDocument)];
|
|
235
235
|
case 3:
|
|
236
|
-
error_4 =
|
|
236
|
+
error_4 = _c.sent();
|
|
237
237
|
console.error(error_4);
|
|
238
238
|
throw error_4;
|
|
239
239
|
case 4: return [2 /*return*/];
|
package/dist/model/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wCAA4F;AAC5F,oCAA6D;AAC7D,kCAAkD;AAClD,6DAAgD;AAChD,4CAAyC;AACzC,gCAAqC;AAqBrC;IAUI,eAAY,IAAY,EAAE,OAAsB;QAPhD,UAAK,GAAG,UAAU,CAAC;QACnB,WAAM,GAAgC;YAClC,SAAS,EAAE,MAAM;YACjB,SAAS,EAAE,MAAM;SACpB,CAAC;QACF,gBAAW,GAAG,IAAI,CAAC;QAGf,kEAAkE;QAClE,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,WAAW,GAAG,CAAC,OAAO,IAA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AAC,CAAC,UAAU;QACxB,OAAO,IAAA,mBAAW,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACI,wBAAQ,GAAf,UAAgB,IAAsC;QAClD,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,UAAU;QACxB,OAAO,IAAA,iCAAsB,EAAC,IAAI,CAAC,WAAW,aAAG,KAAK,EAAE,IAAI,IAAK,IAAI,EAAE,CAAC;IAC5E,CAAC;IACL,YAAC;AAAD,CAAC,AA1QD,IA0QC;AA1QY,sBAAK;AA4QlB,kBAAe,KAAK,CAAC","sourcesContent":["import {Collection, GetOptions, RemoveOptions, ReplaceOptions, UpsertOptions} from 'couchbase';\n\nimport {AutomaticMethodOptions, AutomaticOutput, automateImplementation} from '../automate';\nimport {CustomQuery, CustomQueryPagination} from '../search';\nimport {SchemaTypes, parseSchema} from '../utils';\nimport CouchbaseConnection from '../connection';\nimport {Pagination} from '../pagination';\nimport {generateUUID} from '../uuid';\n\nexport interface AutoModelFields {\n id: string;\n createdAt: Date;\n updatedAt?: Date;\n deleted?: Date;\n _type: string; // type for models/collections\n _scope: string; // scope for collections\n}\n\nexport interface UpdateOptions extends ReplaceOptions {\n silent?: boolean; // whether to updatedAt;\n}\n\nexport interface ModalOptions {\n scope?: string;\n schema?: Record<string, SchemaTypes>;\n graphqlType?: any;\n}\n\nexport class Model {\n collection: Collection;\n collectionName: string;\n scope = '_default';\n schema: Record<string, SchemaTypes> = {\n createdAt: 'date',\n updatedAt: 'date',\n };\n graphqlType = null;\n\n constructor(name: string, options?: ModalOptions) {\n // this.collection = CouchbaseConnection.Instance.getCollection();\n this.collectionName = name;\n if (options) {\n this.graphqlType = (options && options.graphqlType) || null;\n this.scope = (options && options.scope) || '_default';\n this.schema = {\n ...((options && options.schema) || {}),\n createdAt: 'date',\n updatedAt: 'date',\n };\n }\n }\n\n /**\n * Set setGraphqlType\n * setGraphqlType\n */\n public setGraphqlType(gqlType: any): Model {\n this.graphqlType = gqlType;\n return this;\n }\n\n /**\n * Refresh and get default collection from CouchbaseConnection\n * Because CouchbaseConnection is a singleton, sometimes it might be undefined depending when model was created\n * So we have to call it from all model methods\n * to avoid error `Cannot read property 'defaultCollection' of null`\n */\n public fresh(): void {\n // if couchbase connection has been init\n if (CouchbaseConnection.Instance.bucketName) {\n this.collection = CouchbaseConnection.Instance.getCollection();\n }\n }\n\n /** Get this collection\n * getCollection\n */\n public getBucketName(): string {\n return CouchbaseConnection.Instance?.getBucket();\n }\n\n /** Get this collection\n * getCollection\n */\n public couchbaseConnection(): CouchbaseConnection {\n return CouchbaseConnection.Instance;\n }\n\n /** Get this collection\n * getCollection\n */\n public getCollection(): Collection {\n this.fresh();\n return this.collection;\n }\n\n /**\n * create\n */\n public async create<T>(data: T, options?: UpsertOptions): Promise<T & AutoModelFields> {\n this.fresh();\n const id = generateUUID();\n const createdData = {\n id, // let id be override\n ...data,\n createdAt: new Date(),\n updatedAt: new Date(), // same as created at\n _type: this.collectionName,\n _scope: this.scope,\n };\n\n try {\n await this.collection.upsert(createdData.id, createdData, options);\n return parseSchema(this.schema, createdData);\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * findById\n */\n public async findById(id: string, options?: GetOptions): Promise<any & AutoModelFields> {\n this.fresh();\n try {\n const data = await this.collection.get(id, options);\n return parseSchema(this.schema, data.content);\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * update\n */\n public async updateById<T>(id: string, data: T, opt?: UpdateOptions): Promise<T> {\n this.fresh();\n\n const {silent = false, ...options} = opt;\n\n const updatedDocument: any = {\n ...data,\n id,\n _type: this.collectionName, // type and scope must be defined\n _scope: this.scope,\n };\n\n if (!silent) {\n updatedDocument.updatedAt = new Date();\n }\n\n try {\n await this.collection.replace(id, updatedDocument, options);\n return parseSchema(this.schema, updatedDocument);\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * save\n */\n public async save<T>(data: T & {id: string}, opt?: UpdateOptions): Promise<T> {\n this.fresh();\n\n const id = data && data.id;\n\n const {silent = false, ...options} = opt;\n\n const updatedDocument: any = {\n ...data,\n id,\n _type: this.collectionName, // type and scope must be defined\n _scope: this.scope,\n };\n\n if (!silent) {\n updatedDocument.updatedAt = new Date();\n }\n\n try {\n if (!id) {\n throw new Error('document must have id');\n }\n await this.collection.replace(id, updatedDocument, options);\n return parseSchema(this.schema, updatedDocument);\n } catch (error) {\n console.error(error);\n throw error;\n }\n }\n\n public async delete(id: string, options?: RemoveOptions): Promise<boolean> {\n this.fresh();\n try {\n await this.collection.remove(id, options);\n return true;\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * Pagination\n * \n select = ['id', 'createdAt']\n where = {\n where: { owner: { $eq: \"stoqey\" }, _type: { $eq: \"Trade\" } },\n },\n page = 0,\n limit = 10,\n orderBy = { createdAt: \"DESC\" },\n * @param args PaginationArgs\n */\n public async pagination({\n select,\n where,\n orderBy,\n limit,\n page,\n customQuery = {},\n }: {\n select?: any[] | string;\n where?: any;\n orderBy?: any;\n limit?: number;\n page?: number;\n customQuery?: any; // can be $and or any other valid quries\n }): Promise<any[]> {\n this.fresh(); // refresh\n // Where begins here\n let whereEx = {_type: {$eq: this.collectionName}};\n\n if (where) {\n whereEx = {\n ...whereEx,\n ...where,\n };\n }\n\n const bucketName = CouchbaseConnection.Instance.bucketName;\n\n const rows = await Pagination({\n bucketName,\n select,\n where: {where: whereEx, ...customQuery},\n limit,\n page,\n orderBy,\n });\n\n return rows.map((r) => parseSchema(this.schema, r));\n }\n\n /**\n * Run a custom query with model parsing\n * @param { select, query }\n * @returns\n */\n public async customQuery<T>({\n params,\n limit,\n query,\n }: {\n params: any;\n limit: number;\n query: string;\n }): Promise<[T[], CustomQueryPagination]> {\n this.fresh(); // refresh\n // Where begins here\n\n const response = await CustomQuery<T>({\n limit,\n params,\n query,\n });\n\n return response;\n }\n\n public parse<T>(data: T): T {\n this.fresh(); // refresh\n return parseSchema(this.schema, data);\n }\n\n /**\n *\n * @param args AutomaticModelOptions\n * @returns\n */\n public automate(args?: Partial<AutomaticMethodOptions>): AutomaticOutput {\n this.fresh(); // refresh\n return automateImplementation(this.graphqlType, {model: this, ...args});\n }\n}\n\nexport default Model;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wCAA4F;AAC5F,oCAA6D;AAC7D,kCAAkD;AAClD,6DAAgD;AAChD,4CAAyC;AACzC,gCAAqC;AAqBrC;IAUI,eAAY,IAAY,EAAE,OAAsB;QAPhD,UAAK,GAAG,UAAU,CAAC;QACnB,WAAM,GAAgC;YAClC,SAAS,EAAE,MAAM;YACjB,SAAS,EAAE,MAAM;SACpB,CAAC;QACF,gBAAW,GAAG,IAAI,CAAC;QAGf,kEAAkE;QAClE,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,OAAO,EAAE;YACT,IAAI,CAAC,WAAW,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC;YAC5D,IAAI,CAAC,KAAK,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC;YACtD,IAAI,CAAC,MAAM,yBACJ,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,KACtC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GACpB,CAAC;SACL;IACL,CAAC;IAED;;;OAGG;IACI,8BAAc,GAArB,UAAsB,OAAY;QAC9B,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;QAC3B,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,qBAAK,GAAZ;QACI,wCAAwC;QACxC,IAAI,oBAAmB,CAAC,QAAQ,CAAC,UAAU,EAAE;YACzC,IAAI,CAAC,UAAU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KAAK,EAAE,OAAO,IAAK,WAAW,CAAC;gCACvC,KAAK,OAAA;gCACL,IAAI,MAAA;gCACJ,OAAO,SAAA;6BACV,CAAC,EAAA;;wBAPI,IAAI,GAAG,SAOX;wBAEF,sBAAO,IAAI,CAAC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,IAAA,mBAAW,EAAC,KAAI,CAAC,MAAM,EAAE,CAAC,CAAC,EAA3B,CAA2B,CAAC,EAAC;;;;KACvD;IAED;;;;OAIG;IACU,2BAAW,GAAxB,UAA4B,EAQ3B;YAPG,MAAM,YAAA,EACN,KAAK,WAAA,EACL,KAAK,WAAA;;;;;;wBAML,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,UAAU;wBAGP,qBAAM,IAAA,oBAAW,EAAI;gCAClC,KAAK,OAAA;gCACL,MAAM,QAAA;gCACN,KAAK,OAAA;6BACR,CAAC,EAAA;;wBAJI,QAAQ,GAAG,SAIf;wBAEF,sBAAO,QAAQ,EAAC;;;;KACnB;IAEM,qBAAK,GAAZ,UAAgB,IAAO;QACnB,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,UAAU;QACxB,OAAO,IAAA,mBAAW,EAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACI,wBAAQ,GAAf,UAAgB,IAAsC;QAClD,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,UAAU;QACxB,OAAO,IAAA,iCAAsB,EAAC,IAAI,CAAC,WAAW,aAAG,KAAK,EAAE,IAAI,IAAK,IAAI,EAAE,CAAC;IAC5E,CAAC;IACL,YAAC;AAAD,CAAC,AA1QD,IA0QC;AA1QY,sBAAK;AA4QlB,kBAAe,KAAK,CAAC","sourcesContent":["import {Collection, GetOptions, RemoveOptions, ReplaceOptions, UpsertOptions} from 'couchbase';\n\nimport {AutomaticMethodOptions, AutomaticOutput, automateImplementation} from '../automate';\nimport {CustomQuery, CustomQueryPagination} from '../search';\nimport {SchemaTypes, parseSchema} from '../utils';\nimport CouchbaseConnection from '../connection';\nimport {Pagination} from '../pagination';\nimport {generateUUID} from '../uuid';\n\nexport interface AutoModelFields {\n id: string;\n createdAt: Date;\n updatedAt?: Date;\n deleted?: Date;\n _type: string; // type for models/collections\n _scope: string; // scope for collections\n}\n\nexport interface UpdateOptions extends ReplaceOptions {\n silent?: boolean; // whether to updatedAt;\n}\n\nexport interface ModalOptions {\n scope?: string;\n schema?: Record<string, SchemaTypes>;\n graphqlType?: any;\n}\n\nexport class Model {\n collection: Collection;\n collectionName: string;\n scope = '_default';\n schema: Record<string, SchemaTypes> = {\n createdAt: 'date',\n updatedAt: 'date',\n };\n graphqlType = null;\n\n constructor(name: string, options?: ModalOptions) {\n // this.collection = CouchbaseConnection.Instance.getCollection();\n this.collectionName = name;\n if (options) {\n this.graphqlType = (options && options.graphqlType) || null;\n this.scope = (options && options.scope) || '_default';\n this.schema = {\n ...((options && options.schema) || {}),\n createdAt: 'date',\n updatedAt: 'date',\n };\n }\n }\n\n /**\n * Set setGraphqlType\n * setGraphqlType\n */\n public setGraphqlType(gqlType: any): Model {\n this.graphqlType = gqlType;\n return this;\n }\n\n /**\n * Refresh and get default collection from CouchbaseConnection\n * Because CouchbaseConnection is a singleton, sometimes it might be undefined depending when model was created\n * So we have to call it from all model methods\n * to avoid error `Cannot read property 'defaultCollection' of null`\n */\n public fresh(): void {\n // if couchbase connection has been init\n if (CouchbaseConnection.Instance.bucketName) {\n this.collection = CouchbaseConnection.Instance.getCollection();\n }\n }\n\n /** Get this collection\n * getCollection\n */\n public getBucketName(): string {\n return CouchbaseConnection.Instance?.getBucket();\n }\n\n /** Get this collection\n * getCollection\n */\n public couchbaseConnection(): CouchbaseConnection {\n return CouchbaseConnection.Instance;\n }\n\n /** Get this collection\n * getCollection\n */\n public getCollection(): Collection {\n this.fresh();\n return this.collection;\n }\n\n /**\n * create\n */\n public async create<T>(data: T, options?: UpsertOptions): Promise<T & AutoModelFields> {\n this.fresh();\n const id = generateUUID();\n const createdData = {\n id, // let id be override\n ...data,\n createdAt: new Date(),\n updatedAt: new Date(), // same as created at\n _type: this.collectionName,\n _scope: this.scope,\n };\n\n try {\n await this.collection.upsert(createdData.id, createdData, options);\n return parseSchema(this.schema, createdData);\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * findById\n */\n public async findById(id: string, options?: GetOptions): Promise<any & AutoModelFields> {\n this.fresh();\n try {\n const data = await this.collection.get(id, options);\n return parseSchema(this.schema, data.content);\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * update\n */\n public async updateById<T>(id: string, data: T, opt?: UpdateOptions): Promise<T> {\n this.fresh();\n\n const {silent = false, ...options} = opt || {};\n\n const updatedDocument: any = {\n ...data,\n id,\n _type: this.collectionName, // type and scope must be defined\n _scope: this.scope,\n };\n\n if (!silent) {\n updatedDocument.updatedAt = new Date();\n }\n\n try {\n await this.collection.replace(id, updatedDocument, options);\n return parseSchema(this.schema, updatedDocument);\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * save\n */\n public async save<T>(data: T & {id: string}, opt?: UpdateOptions): Promise<T> {\n this.fresh();\n\n const id = data && data.id;\n\n const {silent = false, ...options} = opt || {};\n\n const updatedDocument: any = {\n ...data,\n id,\n _type: this.collectionName, // type and scope must be defined\n _scope: this.scope,\n };\n\n if (!silent) {\n updatedDocument.updatedAt = new Date();\n }\n\n try {\n if (!id) {\n throw new Error('document must have id');\n }\n await this.collection.replace(id, updatedDocument, options);\n return parseSchema(this.schema, updatedDocument);\n } catch (error) {\n console.error(error);\n throw error;\n }\n }\n\n public async delete(id: string, options?: RemoveOptions): Promise<boolean> {\n this.fresh();\n try {\n await this.collection.remove(id, options);\n return true;\n } catch (error) {\n throw error;\n }\n }\n\n /**\n * Pagination\n * \n select = ['id', 'createdAt']\n where = {\n where: { owner: { $eq: \"stoqey\" }, _type: { $eq: \"Trade\" } },\n },\n page = 0,\n limit = 10,\n orderBy = { createdAt: \"DESC\" },\n * @param args PaginationArgs\n */\n public async pagination({\n select,\n where,\n orderBy,\n limit,\n page,\n customQuery = {},\n }: {\n select?: any[] | string;\n where?: any;\n orderBy?: any;\n limit?: number;\n page?: number;\n customQuery?: any; // can be $and or any other valid quries\n }): Promise<any[]> {\n this.fresh(); // refresh\n // Where begins here\n let whereEx = {_type: {$eq: this.collectionName}};\n\n if (where) {\n whereEx = {\n ...whereEx,\n ...where,\n };\n }\n\n const bucketName = CouchbaseConnection.Instance.bucketName;\n\n const rows = await Pagination({\n bucketName,\n select,\n where: {where: whereEx, ...customQuery},\n limit,\n page,\n orderBy,\n });\n\n return rows.map((r) => parseSchema(this.schema, r));\n }\n\n /**\n * Run a custom query with model parsing\n * @param { select, query }\n * @returns\n */\n public async customQuery<T>({\n params,\n limit,\n query,\n }: {\n params: any;\n limit: number;\n query: string;\n }): Promise<[T[], CustomQueryPagination]> {\n this.fresh(); // refresh\n // Where begins here\n\n const response = await CustomQuery<T>({\n limit,\n params,\n query,\n });\n\n return response;\n }\n\n public parse<T>(data: T): T {\n this.fresh(); // refresh\n return parseSchema(this.schema, data);\n }\n\n /**\n *\n * @param args AutomaticModelOptions\n * @returns\n */\n public automate(args?: Partial<AutomaticMethodOptions>): AutomaticOutput {\n this.fresh(); // refresh\n return automateImplementation(this.graphqlType, {model: this, ...args});\n }\n}\n\nexport default Model;\n"]}
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type SortType = 'ASC' | 'DESC';
|
|
2
2
|
/**
|
|
3
3
|
* Result expressions ALL | DISTINCT
|
|
4
4
|
* */
|
|
5
|
-
export
|
|
5
|
+
export type ReturnResultType = '$all' | '$distinct';
|
|
6
6
|
/**
|
|
7
7
|
* Result expressions RAW | ELEMENT | VALUE
|
|
8
8
|
* */
|
|
9
|
-
export
|
|
9
|
+
export type ResultExprType = '$raw' | '$element' | '$value';
|
|
10
10
|
/**
|
|
11
11
|
* List of aggregation functions.
|
|
12
12
|
* */
|
|
13
|
-
export
|
|
13
|
+
export type AggType = '$arrayAgg' | '$avg' | '$mean' | '$count' | '$countn' | '$max' | '$median' | '$min' | '$stddev' | '$stddevPop' | '$stddevSamp' | '$sum' | '$variance' | '$variancePop' | '$varianceSamp' | '$varPop' | '$varSamp';
|
|
14
14
|
/**
|
|
15
15
|
* List of Boolean comparison operators.
|
|
16
16
|
* */
|
|
17
|
-
export
|
|
17
|
+
export type ComparisonEmptyOperatorType = '$isNull' | '$isNotNull' | '$isMissing' | '$isNotMissing' | '$isValued' | '$isNotValued';
|
|
18
18
|
/**
|
|
19
19
|
* List of Numeric comparison operators.
|
|
20
20
|
* */
|
|
21
|
-
export
|
|
21
|
+
export type ComparisonSingleOperatorType = '$eq' | '$neq' | '$gt' | '$gte' | '$lt' | '$lte';
|
|
22
22
|
/**
|
|
23
23
|
* List of String comparison operators.
|
|
24
24
|
* */
|
|
25
|
-
export
|
|
25
|
+
export type ComparisonSingleStringOperatorType = '$like' | '$notLike';
|
|
26
26
|
/**
|
|
27
27
|
* List of Range comparison operators.
|
|
28
28
|
* */
|
|
29
|
-
export
|
|
29
|
+
export type ComparisonMultipleOperatorType = '$btw' | '$notBtw';
|
|
30
30
|
/**
|
|
31
31
|
* List of Logical operators.
|
|
32
32
|
* */
|
|
33
|
-
export
|
|
33
|
+
export type LogicalOperatorType = '$and' | '$or' | '$not';
|
|
34
34
|
/**
|
|
35
35
|
* Collection Select Operator.
|
|
36
36
|
* */
|
|
37
|
-
export
|
|
37
|
+
export type CollectionSelectOperator = '$any' | '$every';
|
|
38
38
|
/**
|
|
39
39
|
* Collection IN and WITHIN Operators.
|
|
40
40
|
* */
|
|
41
|
-
export
|
|
41
|
+
export type CollectionInWithinOperator = '$in' | '$within';
|
|
42
42
|
/**
|
|
43
43
|
* List of Collection IN and WITHIN Operators.
|
|
44
44
|
* */
|
|
45
|
-
export
|
|
45
|
+
export type CollectionSatisfiesOperator = '$satisfies';
|
|
46
46
|
export interface CollectionInWithinOperatorValue {
|
|
47
47
|
search_expr: unknown;
|
|
48
48
|
target_expr: unknown;
|
|
@@ -56,7 +56,7 @@ export interface CollectionInWithinOperatorValue {
|
|
|
56
56
|
* {$in:{search_expr: 'search', target_expr: 'address', $not: true}}
|
|
57
57
|
* ```
|
|
58
58
|
* */
|
|
59
|
-
export
|
|
59
|
+
export type CollectionInWithinOperatorType = {
|
|
60
60
|
[key in CollectionInWithinOperator]?: CollectionInWithinOperatorValue;
|
|
61
61
|
};
|
|
62
62
|
/**
|
|
@@ -75,7 +75,7 @@ export interface CollectionExpressionType {
|
|
|
75
75
|
* {$any: {$expr: [{$in:{search_expr: 'search', target_expr: 'address', $not: true} }], $satisfied:{address: '10'}}}
|
|
76
76
|
* ```
|
|
77
77
|
* */
|
|
78
|
-
export
|
|
78
|
+
export type CollectionSelectOperatorType = {
|
|
79
79
|
[key in CollectionSelectOperator]?: CollectionExpressionType;
|
|
80
80
|
};
|
|
81
81
|
/**
|
|
@@ -87,7 +87,7 @@ export declare type CollectionSelectOperatorType = {
|
|
|
87
87
|
* ```
|
|
88
88
|
*
|
|
89
89
|
* */
|
|
90
|
-
export
|
|
90
|
+
export type ComparisonWhereExpr = {
|
|
91
91
|
[key in ComparisonEmptyOperatorType | ComparisonSingleOperatorType | ComparisonMultipleOperatorType | ComparisonSingleStringOperatorType]?: string | number | boolean | (number | string)[];
|
|
92
92
|
};
|
|
93
93
|
/**
|
|
@@ -99,7 +99,7 @@ export declare type ComparisonWhereExpr = {
|
|
|
99
99
|
* ```
|
|
100
100
|
*
|
|
101
101
|
* */
|
|
102
|
-
export
|
|
102
|
+
export type FieldWhereExpr = Record<string, string | number | boolean | ComparisonWhereExpr> | LogicalWhereExpr;
|
|
103
103
|
/**
|
|
104
104
|
* Structure of Logical WHERE expression
|
|
105
105
|
*
|
|
@@ -109,7 +109,7 @@ export declare type FieldWhereExpr = Record<string, string | number | boolean |
|
|
|
109
109
|
* ```
|
|
110
110
|
*
|
|
111
111
|
* */
|
|
112
|
-
export
|
|
112
|
+
export type LogicalWhereExpr = {
|
|
113
113
|
[key in LogicalOperatorType]?: FieldWhereExpr[];
|
|
114
114
|
} | {
|
|
115
115
|
[key: string]: FieldWhereExpr;
|
|
@@ -138,7 +138,7 @@ export interface IField {
|
|
|
138
138
|
* ```
|
|
139
139
|
*
|
|
140
140
|
* */
|
|
141
|
-
export
|
|
141
|
+
export type ISelectAggType = {
|
|
142
142
|
[key in AggType]?: ISelectFieldType;
|
|
143
143
|
};
|
|
144
144
|
/**
|
|
@@ -164,7 +164,7 @@ export interface ISelectFieldType {
|
|
|
164
164
|
* ```
|
|
165
165
|
*
|
|
166
166
|
* */
|
|
167
|
-
export
|
|
167
|
+
export type ISelectResultExprType = {
|
|
168
168
|
[key in ResultExprType]?: ISelectAggType | ISelectFieldType;
|
|
169
169
|
};
|
|
170
170
|
/**
|
|
@@ -176,7 +176,7 @@ export declare type ISelectResultExprType = {
|
|
|
176
176
|
* ```
|
|
177
177
|
*
|
|
178
178
|
* */
|
|
179
|
-
export
|
|
179
|
+
export type ISelectReturnResultType = {
|
|
180
180
|
[key in ReturnResultType]?: ISelectResultExprType | ISelectAggType | ISelectFieldType;
|
|
181
181
|
};
|
|
182
182
|
/**
|
|
@@ -188,7 +188,7 @@ export declare type ISelectReturnResultType = {
|
|
|
188
188
|
* ```
|
|
189
189
|
*
|
|
190
190
|
* */
|
|
191
|
-
export
|
|
191
|
+
export type ISelectType = ISelectReturnResultType | ISelectResultExprType | ISelectAggType | ISelectFieldType;
|
|
192
192
|
/**
|
|
193
193
|
* LET expression
|
|
194
194
|
* */
|
|
@@ -218,7 +218,7 @@ export interface IConditionExpr {
|
|
|
218
218
|
/**
|
|
219
219
|
* Types of supported index statements
|
|
220
220
|
* */
|
|
221
|
-
export
|
|
221
|
+
export type IndexType = 'CREATE' | 'BUILD' | 'DROP' | 'CREATE PRIMARY';
|
|
222
222
|
/**
|
|
223
223
|
* Index ON clause types
|
|
224
224
|
* */
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -14,7 +14,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
18
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
19
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
20
|
switch (op[0]) {
|
|
@@ -24,7 +24,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
24
24
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
25
|
function step(op) {
|
|
26
26
|
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (_) try {
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
28
|
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
29
|
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
30
|
switch (op[0]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "couchset",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Couchbase ORM & Automatic GraphQL API(Resolver/Queries)",
|
|
5
5
|
"private": false,
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"homepage": "https://github.com/couchset/couchset#readme",
|
|
63
63
|
"devDependencies": {
|
|
64
64
|
"@types/chai": "^4.2.14",
|
|
65
|
-
"@types/couchbase": "^2.4.
|
|
65
|
+
"@types/couchbase": "^2.4.9",
|
|
66
66
|
"@types/debug": "^4.1.7",
|
|
67
67
|
"@types/express": "^4.17.13",
|
|
68
68
|
"@types/lodash": "^4.14.168",
|
|
@@ -96,14 +96,14 @@
|
|
|
96
96
|
"typescript": ">=2.0"
|
|
97
97
|
},
|
|
98
98
|
"dependencies": {
|
|
99
|
-
"couchbase": "^
|
|
99
|
+
"couchbase": "^4.4.2",
|
|
100
100
|
"debug": "^4.3.1",
|
|
101
101
|
"dotenv": "^10.0.0",
|
|
102
102
|
"graphql": "^15.6.0",
|
|
103
103
|
"graphql-redis-subscriptions": "^2.4.0",
|
|
104
104
|
"graphql-tag": "^2.12.5",
|
|
105
105
|
"graphql-type-json": "^0.3.2",
|
|
106
|
-
"jsonwebtoken": "^
|
|
106
|
+
"jsonwebtoken": "^9.0.2",
|
|
107
107
|
"lodash": "^4.17.20",
|
|
108
108
|
"ts-morph": "^12.0.0",
|
|
109
109
|
"type-graphql": "^1.1.1",
|