@coffer-org/sdk 3.1.0 → 3.2.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.
@@ -19,9 +19,11 @@ export interface Condition {
19
19
  export type Values = Record<string, unknown>;
20
20
  export declare const COMPILABLE_SCALAR_OPS: Set<string>;
21
21
  export declare const COMPILABLE_ARRAY_OPS: Set<string>;
22
+ export declare const COMPILABLE_MEMBER_OPS: Set<string>;
22
23
  export declare function evalCondition(cond: Condition | undefined, values: Values): boolean;
23
24
  export declare function resolveFlag(v: boolean | Condition | undefined, values: Values): boolean;
24
25
  export declare function conditionKeys(cond: Condition | undefined): string[];
26
+ export declare function conditionOps(cond: Condition | undefined, field: string): string[];
25
27
  export declare function visibleOptions<T extends {
26
28
  value?: string;
27
29
  when?: Condition;
package/dist/condition.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import sift from 'sift';
2
2
  export const COMPILABLE_SCALAR_OPS = new Set(['$eq', '$ne', '$gt', '$gte', '$lt', '$lte']);
3
3
  export const COMPILABLE_ARRAY_OPS = new Set(['$in', '$nin']);
4
+ export const COMPILABLE_MEMBER_OPS = new Set(['$contains']);
4
5
  const createEqualsOperation = sift
5
6
  .createEqualsOperation;
6
7
  const isScalar = (v) => typeof v === 'string' || typeof v === 'number' || typeof v === 'boolean';
@@ -80,6 +81,27 @@ export function conditionKeys(cond) {
80
81
  }
81
82
  return [...new Set(out)];
82
83
  }
84
+ export function conditionOps(cond, field) {
85
+ if (!cond)
86
+ return [];
87
+ const out = [];
88
+ for (const [key, spec] of Object.entries(cond)) {
89
+ if (spec === undefined)
90
+ continue;
91
+ if (key === '$and' || key === '$or') {
92
+ for (const c of spec)
93
+ out.push(...conditionOps(c, field));
94
+ continue;
95
+ }
96
+ if (key !== field)
97
+ continue;
98
+ if (typeof spec === 'object' && spec !== null && !Array.isArray(spec))
99
+ out.push(...Object.keys(spec));
100
+ else
101
+ out.push('$eq');
102
+ }
103
+ return [...new Set(out)];
104
+ }
83
105
  export function visibleOptions(options, values, keep) {
84
106
  const kept = keep === undefined ? undefined : new Set(Array.isArray(keep) ? keep : [keep]);
85
107
  return options.filter((o) => (kept !== undefined && o.value !== undefined && kept.has(o.value)) || (o.when ? evalCondition(o.when, values) : true));
package/dist/showcase.js CHANGED
@@ -1,5 +1,9 @@
1
- import { COMPILABLE_SCALAR_OPS, COMPILABLE_ARRAY_OPS } from "./condition.js";
2
- const COMPILABLE_OPS = new Set([...COMPILABLE_SCALAR_OPS, ...COMPILABLE_ARRAY_OPS]);
1
+ import { COMPILABLE_SCALAR_OPS, COMPILABLE_ARRAY_OPS, COMPILABLE_MEMBER_OPS } from "./condition.js";
2
+ const COMPILABLE_OPS = new Set([
3
+ ...COMPILABLE_SCALAR_OPS,
4
+ ...COMPILABLE_ARRAY_OPS,
5
+ ...COMPILABLE_MEMBER_OPS,
6
+ ]);
3
7
  function assertCompilableOps(cond, id) {
4
8
  for (const [key, spec] of Object.entries(cond)) {
5
9
  if (spec === undefined)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffer-org/sdk",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"