rads-db 0.1.65 → 0.1.67

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/index.cjs CHANGED
@@ -642,7 +642,8 @@ async function fillDenormFieldsBeforePut(computedContext, docUpdates, ctx) {
642
642
 
643
643
  function generateMethods(schema, validators, options) {
644
644
  const drivers = {};
645
- const opts = { computed: {}, driver: memory(), ...options };
645
+ const opts = { computed: {}, driver: memory(), beforeGet: () => {
646
+ }, ...options };
646
647
  const db = {
647
648
  _schema: schema,
648
649
  uploadFile(args) {
@@ -682,15 +683,18 @@ function generateMethods(schema, validators, options) {
682
683
  const { precomputedFields } = schema[key];
683
684
  db[handle] = {
684
685
  getAgg: async (args, ctx) => {
685
- if (!args?.agg)
686
+ args = { ...args, where: { ...args?.where } };
687
+ if (!args.agg)
686
688
  throw new Error(`Please provide 'agg' argument`);
687
689
  ctx = { ...opts.context, ...ctx };
690
+ await opts.beforeGet(args, ctx, computedContext);
688
691
  const result = await driverInstance.getAgg(args, ctx);
689
692
  return result;
690
693
  },
691
694
  get: async (args, ctx) => {
692
- args = args || {};
695
+ args = { ...args, where: { ...args?.where } };
693
696
  ctx = { ...opts.context, ...ctx };
697
+ await opts.beforeGet(args, ctx, computedContext);
694
698
  const result = await driverInstance.get(args, ctx);
695
699
  if (result && args.include)
696
700
  await handleInclude(computedContext, args.include, [result], ctx);
@@ -699,8 +703,9 @@ function generateMethods(schema, validators, options) {
699
703
  return result;
700
704
  },
701
705
  getMany: async (args, ctx) => {
702
- args = args || {};
706
+ args = { ...args, where: { ...args?.where } };
703
707
  ctx = { ...opts.context, ...ctx };
708
+ await opts.beforeGet(args, ctx, computedContext);
704
709
  const result = await driverInstance.getMany(args, ctx);
705
710
  if (args.include)
706
711
  await handleInclude(computedContext, args.include, result.nodes, ctx);
@@ -708,8 +713,9 @@ function generateMethods(schema, validators, options) {
708
713
  return result;
709
714
  },
710
715
  getAll: async (args, ctx) => {
711
- args = args || {};
716
+ args = { ...args, where: { ...args?.where } };
712
717
  ctx = { ...opts.context, ...ctx };
718
+ await opts.beforeGet(args, ctx, computedContext);
713
719
  const result = await driverInstance.getAll(args, ctx);
714
720
  if (args.include)
715
721
  await handleInclude(computedContext, args.include, result, ctx);
package/dist/index.d.ts CHANGED
@@ -141,6 +141,7 @@ interface CreateRadsArgs {
141
141
  fileUploadDriver?: FileUploadDriver;
142
142
  skipComputed?: boolean;
143
143
  computed?: Record<string, Record<string, Function>>;
144
+ beforeGet?: (args: GetArgsAny, ctx: RadsRequestContext, context: ComputedContext) => MaybePromise<void>;
144
145
  context?: Record<string, any> & RadsRequestContext;
145
146
  }
146
147
  type Schema = Record<string, TypeDefinition>;
package/dist/index.mjs CHANGED
@@ -635,7 +635,8 @@ async function fillDenormFieldsBeforePut(computedContext, docUpdates, ctx) {
635
635
 
636
636
  function generateMethods(schema, validators, options) {
637
637
  const drivers = {};
638
- const opts = { computed: {}, driver: memory(), ...options };
638
+ const opts = { computed: {}, driver: memory(), beforeGet: () => {
639
+ }, ...options };
639
640
  const db = {
640
641
  _schema: schema,
641
642
  uploadFile(args) {
@@ -675,15 +676,18 @@ function generateMethods(schema, validators, options) {
675
676
  const { precomputedFields } = schema[key];
676
677
  db[handle] = {
677
678
  getAgg: async (args, ctx) => {
678
- if (!args?.agg)
679
+ args = { ...args, where: { ...args?.where } };
680
+ if (!args.agg)
679
681
  throw new Error(`Please provide 'agg' argument`);
680
682
  ctx = { ...opts.context, ...ctx };
683
+ await opts.beforeGet(args, ctx, computedContext);
681
684
  const result = await driverInstance.getAgg(args, ctx);
682
685
  return result;
683
686
  },
684
687
  get: async (args, ctx) => {
685
- args = args || {};
688
+ args = { ...args, where: { ...args?.where } };
686
689
  ctx = { ...opts.context, ...ctx };
690
+ await opts.beforeGet(args, ctx, computedContext);
687
691
  const result = await driverInstance.get(args, ctx);
688
692
  if (result && args.include)
689
693
  await handleInclude(computedContext, args.include, [result], ctx);
@@ -692,8 +696,9 @@ function generateMethods(schema, validators, options) {
692
696
  return result;
693
697
  },
694
698
  getMany: async (args, ctx) => {
695
- args = args || {};
699
+ args = { ...args, where: { ...args?.where } };
696
700
  ctx = { ...opts.context, ...ctx };
701
+ await opts.beforeGet(args, ctx, computedContext);
697
702
  const result = await driverInstance.getMany(args, ctx);
698
703
  if (args.include)
699
704
  await handleInclude(computedContext, args.include, result.nodes, ctx);
@@ -701,8 +706,9 @@ function generateMethods(schema, validators, options) {
701
706
  return result;
702
707
  },
703
708
  getAll: async (args, ctx) => {
704
- args = args || {};
709
+ args = { ...args, where: { ...args?.where } };
705
710
  ctx = { ...opts.context, ...ctx };
711
+ await opts.beforeGet(args, ctx, computedContext);
706
712
  const result = await driverInstance.getAll(args, ctx);
707
713
  if (args.include)
708
714
  await handleInclude(computedContext, args.include, result, ctx);
@@ -128,7 +128,9 @@ function getCosmosQuery(schema, entity, args) {
128
128
  }, parameters, where)].filter(x => x);
129
129
  let orderByClause = "";
130
130
  if (args.orderBy) {
131
- const [orderPropFromOrderBy, orderDirection] = args.orderBy.split("_") || [];
131
+ const orderByParts = args.orderBy.split("_");
132
+ const orderPropFromOrderBy = orderByParts.slice(0, -1).join(".");
133
+ const orderDirection = orderByParts.at(-1);
132
134
  const orderProp = orderPropFromOrderBy === "value" ? `r["value"]` : `r.${orderPropFromOrderBy}`;
133
135
  orderByClause = `order by ${orderProp} ${orderDirection}`;
134
136
  }
@@ -83,7 +83,9 @@ function getCosmosQuery(schema, entity, args) {
83
83
  ].filter((x) => x);
84
84
  let orderByClause = "";
85
85
  if (args.orderBy) {
86
- const [orderPropFromOrderBy, orderDirection] = args.orderBy.split("_") || [];
86
+ const orderByParts = args.orderBy.split("_");
87
+ const orderPropFromOrderBy = orderByParts.slice(0, -1).join(".");
88
+ const orderDirection = orderByParts.at(-1);
87
89
  const orderProp = orderPropFromOrderBy === "value" ? `r["value"]` : `r.${orderPropFromOrderBy}`;
88
90
  orderByClause = `order by ${orderProp} ${orderDirection}`;
89
91
  }
package/package.json CHANGED
@@ -34,7 +34,7 @@
34
34
  "require": "./integrations/*.cjs"
35
35
  }
36
36
  },
37
- "version": "0.1.65",
37
+ "version": "0.1.67",
38
38
  "description": "Say goodbye to boilerplate code and hello to efficient and elegant syntax.",
39
39
  "keywords": [],
40
40
  "author": "",