@routier/core 0.3.0 → 0.5.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/README.md +2 -2
- package/dist/index.cjs +549 -462
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +554 -462
- package/dist/index.js.map +1 -1
- package/dist/plugins/TelemetryDbPlugin.d.ts +43 -0
- package/dist/plugins/index.cjs +538 -24
- package/dist/plugins/index.cjs.map +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +544 -22
- package/dist/plugins/index.js.map +1 -1
- package/dist/plugins/query/QueryOptionsCollection.d.ts +13 -0
- package/dist/plugins/query/explain.d.ts +82 -0
- package/dist/plugins/query/formatExplanation.d.ts +9 -0
- package/dist/plugins/query/index.d.ts +2 -0
- package/dist/plugins/query/types.d.ts +11 -0
- package/dist/plugins/types.d.ts +43 -1
- package/dist/plugins/wire/types.d.ts +17 -1
- package/dist/utilities/index.cjs +43 -12
- package/dist/utilities/index.cjs.map +1 -1
- package/dist/utilities/index.js +43 -12
- package/dist/utilities/index.js.map +1 -1
- package/package.json +6 -10
- package/dist/capabilities/Capability.d.ts +0 -11
- package/dist/capabilities/PerformanceCapability.d.ts +0 -13
- package/dist/capabilities/TracingCapability.d.ts +0 -11
- package/dist/capabilities/index.cjs +0 -820
- package/dist/capabilities/index.cjs.map +0 -1
- package/dist/capabilities/index.d.ts +0 -4
- package/dist/capabilities/index.js +0 -808
- package/dist/capabilities/index.js.map +0 -1
- package/dist/capabilities/performance/PerformanceTracker.d.ts +0 -11
- package/dist/capabilities/tracing/CallTraceManager.d.ts +0 -12
- package/dist/capabilities/types.d.ts +0 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilities/index.cjs","sources":["webpack://@routier/core/./src/assertions/index.ts","webpack://@routier/core/./src/expressions/utils.ts","webpack://@routier/core/./src/plugins/query/QueryOptionsCollection.ts","webpack://@routier/core/./src/utilities/dates.ts","webpack://@routier/core/./src/utilities/logger.ts","webpack://@routier/core/./src/utilities/strings.ts","webpack://@routier/core/./src/utilities/uuid.ts","webpack://@routier/core/webpack/runtime/define_property_getters","webpack://@routier/core/webpack/runtime/has_own_property","webpack://@routier/core/webpack/runtime/make_namespace_object","webpack://@routier/core/./src/utilities/arrays.ts","webpack://@routier/core/./src/utilities/objects.ts","webpack://@routier/core/./src/utilities/runtime.ts","webpack://@routier/core/./src/utilities/replication.ts","webpack://@routier/core/./src/utilities/queryOptionsCollection.ts","webpack://@routier/core/./src/utilities/dbPluginEventUtils.ts","webpack://@routier/core/./src/utilities/functions.ts","webpack://@routier/core/./src/utilities/unsafeCast.ts","webpack://@routier/core/./src/utilities/index.ts"],"sourcesContent":["import { EXPRESSION_TYPES } from \"../expressions/constants\";\nimport { ComparatorExpression, EmptyExpression, Expression, ExpressionType, NotParsableExpression, OperatorExpression, PropertyExpression, ValueExpression } from \"../expressions/types\";\nimport { isDate } from \"../utilities\";\n\nexport function assertDate(data: unknown): asserts data is Date {\n if (isDate(data) === false) {\n throw new TypeError('Value is not a Date');\n }\n}\n\nexport function assertIsNotNull<T>(data: T | null | undefined, message?: string | (() => string)): asserts data is NonNullable<T> {\n if (data == null) {\n if (message == null) {\n throw new TypeError('Assertion failed, data is null');\n }\n\n if (typeof message === \"string\") {\n throw new TypeError(message);\n }\n\n throw new TypeError(message());\n }\n}\n\nexport function assertIsArray<T>(data: unknown, message?: string): asserts data is T[] {\n if (!Array.isArray(data)) {\n throw new TypeError(message ?? 'Assertion failed, data is not of type Array');\n }\n}\n\nexport function assertString(data: unknown, message?: string): asserts data is string {\n if (typeof data !== \"string\") {\n throw new TypeError(message ?? 'Assertion failed, data is not of type String');\n }\n}\n\nexport function assertInstanceOf<T extends new (...args: any[]) => any>(value: unknown, Instance: T): asserts value is T {\n if (value instanceof Instance) {\n return;\n }\n\n if (value != null && typeof value === \"object\" && \"constructor\" in value) {\n throw new TypeError(`value is not instance of type. Type: ${value.constructor.name}`);\n }\n\n throw new TypeError(`value is not instance of type`);\n}\n\nexport function assertIsNumber(value: unknown): asserts value is number {\n if (typeof value !== \"number\") {\n throw new TypeError(\"value is not of type `number`\");\n }\n}\n\n\nfunction isObjectWithType(value: unknown): value is Record<\"type\", unknown> {\n return typeof value === \"object\" && value !== null && \"type\" in value;\n}\n\n/**\n * Type guard: narrows `value` to `Expression` when it is an object with a valid `type` property.\n */\nexport function isExpression(value: unknown): value is Expression {\n return isObjectWithType(value) && EXPRESSION_TYPES.includes(value.type as ExpressionType);\n}\n\n/**\n * Type guard: narrows `value` to `OperatorExpression` when it is an object with `type === \"operator\"`.\n */\nexport function isOperatorExpression(value: unknown): value is OperatorExpression {\n return isObjectWithType(value) && value.type === \"operator\";\n}\n\n/**\n * Type guard: narrows `value` to `ComparatorExpression` when it is an object with `type === \"comparator\"`.\n */\nexport function isComparatorExpression(value: unknown): value is ComparatorExpression {\n return isObjectWithType(value) && value.type === \"comparator\";\n}\n\n/**\n * Type guard: narrows `value` to `PropertyExpression` when it is an object with `type === \"property\"`.\n */\nexport function isPropertyExpression(value: unknown): value is PropertyExpression {\n return isObjectWithType(value) && value.type === \"property\";\n}\n\n/**\n * Type guard: narrows `value` to `ValueExpression` when it is an object with `type === \"value\"`.\n */\nexport function isValueExpression(value: unknown): value is ValueExpression {\n return isObjectWithType(value) && value.type === \"value\";\n}\n\n/**\n * Type guard: narrows `value` to `EmptyExpression` when it is an object with `type === \"empty\"`.\n */\nexport function isEmptyExpression(value: unknown): value is EmptyExpression {\n return isObjectWithType(value) && value.type === \"empty\";\n}\n\n/**\n * Type guard: narrows `value` to `NotParsableExpression` when it is an object with `type === \"not-parsable\"`.\n */\nexport function isNotParsableExpression(value: unknown): value is NotParsableExpression {\n return isObjectWithType(value) && value.type === \"not-parsable\";\n}","import { PropertyInfo } from \"../schema\";\nimport { Expression, PropertyExpression } from \"./types\";\n\n/**\n * Extracts all properties referenced in an expression\n * @param expression The expression to analyze\n * @returns Array of PropertyInfo objects referenced in the expression\n */\nexport function getProperties(expression: Expression): PropertyInfo<any>[] {\n const properties: PropertyInfo<any>[] = [];\n\n function traverse(expr: Expression) {\n // If this is a property expression, add it to our collection\n if (expr.type === \"property\") {\n properties.push((expr as PropertyExpression).property);\n }\n\n // Traverse left and right expressions if they exist\n if (expr.left) {\n traverse(expr.left);\n }\n if (expr.right) {\n traverse(expr.right);\n }\n }\n\n traverse(expression);\n return properties;\n}\n\nexport function forEach(expression: Expression, callback: (expression: Expression) => boolean) {\n function traverse(expr: Expression): boolean {\n // Call the callback for this expression\n // If callback returns false, stop traversing\n if (!callback(expr)) {\n return false;\n }\n\n // Traverse left and right expressions if they exist\n if (expr.left) {\n if (!traverse(expr.left)) {\n return false;\n }\n }\n if (expr.right) {\n if (!traverse(expr.right)) {\n return false;\n }\n }\n\n return true;\n }\n\n traverse(expression);\n}","import { isPropertyExpression } from \"../../assertions\";\nimport { forEach } from \"../../expressions/utils\";\nimport { QueryOption, QueryOptionName, QueryOptionExecutionTarget, QueryOptionValueMap } from \"./types\";\n\nexport type QueryCollectionItem<T, K extends QueryOptionName> = { index: number, option: QueryOption<T, K> };\n\nexport class QueryOptionsCollection<T> {\n\n private options: Map<QueryOptionName, QueryCollectionItem<any, any>[]> = new Map<QueryOptionName, QueryCollectionItem<any, any>[]>();\n private nextExecutionTarget: QueryOptionExecutionTarget = \"database\";\n private nextIndex: number = 0;\n private enumeratedItems: QueryCollectionItem<any, any>[] = [];\n\n get items() {\n return this.options;\n }\n\n get isEmpty() {\n return this.items.size === 0;\n }\n\n static EMPTY<R>() {\n return new QueryOptionsCollection<R>();\n }\n\n static isEmpty<T>(options: QueryOptionsCollection<T>) {\n return options.isEmpty;\n }\n\n add<K extends QueryOptionName>(name: K, value: QueryOption<T, K>[\"value\"]) {\n\n if (name === \"map\") {\n const mapValue = value as QueryOptionValueMap<T>[\"map\"];\n\n // Evaluate the map value to see if we are renaming properties, \n // if we are we need to perform everything after in memory\n if (mapValue.fields.some(x => x.isRename === true) || mapValue.fields.some(x => x.property?.isUnmapped === true)) {\n // Cut over to memory execution since we are renaming a property with .map\n // We do not want to figure out how the new name flows through the entire query\n this.nextExecutionTarget = \"memory\";\n }\n }\n\n if (name === \"filter\") {\n // Need to check for unmapped and renamed properties\n const filterValue = value as QueryOptionValueMap<T>[\"filter\"];\n\n // A tautology (`x => true`) filters nothing — skip it entirely so\n // plugins never see it\n if (filterValue.expression.type === \"empty\") {\n return;\n }\n\n if (filterValue.expression.type === \"not-parsable\") {\n this.nextExecutionTarget = \"memory\";\n } else {\n forEach(filterValue.expression, (expression) => {\n\n if (isPropertyExpression(expression) && expression.property.isUnmapped) {\n // Cut over to memory execution, unmapped properties are not in the database and\n // cannot be queried\n this.nextExecutionTarget = \"memory\";\n return false;\n }\n\n if (isPropertyExpression(expression) && expression.property.hasRenamedSegments) {\n // Cut over to memory execution: the plugin stores data under the\n // `from` (storage) names, but filter selectors reference the\n // in-memory names. Memory execution runs after deserialization,\n // where the in-memory names exist\n this.nextExecutionTarget = \"memory\";\n return false;\n }\n\n return true;\n });\n }\n }\n\n if (name === \"sort\") {\n const sortValue = value as QueryOptionValueMap<T>[\"sort\"];\n\n // Same rule as filters: sort selectors reference in-memory names, which\n // only exist after deserialization when the property is renamed or unmapped\n if (sortValue.property != null && (sortValue.property.isUnmapped || sortValue.property.hasRenamedSegments)) {\n this.nextExecutionTarget = \"memory\";\n }\n }\n\n if (name === \"nearest\") {\n const nearestValue = value as QueryOptionValueMap<T>[\"nearest\"];\n\n // Same rule as sort, and for the same reason: the plugin stores the vector under\n // the `from` name, and an unmapped property is not stored at all. Both are only\n // readable after deserialization, which is where memory execution runs.\n //\n // This is also what lets every translator's in-memory fallback read the column by\n // its resolved name — anything whose storage name differs never reaches them.\n if (nearestValue.property != null && (nearestValue.property.isUnmapped || nearestValue.property.hasRenamedSegments)) {\n this.nextExecutionTarget = \"memory\";\n }\n }\n\n if (name === \"join\") {\n const joinValue = value as QueryOptionValueMap<T>[\"join\"];\n\n // A join whose two sides live on different plugins cannot be sent to EITHER of\n // them — neither can read the other's rows — so the option itself belongs to the\n // memory half, where the datastore interprets it.\n //\n // Set BEFORE the item is created, unlike `nearest`'s ratchet below, because this\n // moves the join option itself rather than everything after it.\n if (joinValue.crossPlugin === true) {\n this.nextExecutionTarget = \"memory\";\n }\n }\n\n const item: QueryCollectionItem<T, K> = {\n index: this.nextIndex,\n option: {\n name,\n target: this.nextExecutionTarget,\n value\n }\n }\n\n this.nextIndex++;\n\n const found = this.options.get(name);\n\n this.options.set(name, [...found ?? [], item]);\n\n if (name === \"nearest\") {\n // Everything AFTER a similarity search runs in memory, whatever the backend.\n //\n // Whether the search was pushed down is a fact about the plugin, which this\n // collection cannot see — so a later option is only safe if it runs after the\n // scoring definitely happened, and in memory is the only place that is true of.\n //\n // The failure this prevents is silent. `.nearest(x => x.embedding, v, 10).take(3)`\n // sends `LIMIT 3` to a backend that ignored the ordering, so three arbitrary rows\n // come back and get scored — three real rows, in a plausible order, and not the\n // three nearest. Nothing errors.\n //\n // A plugin that DID push the search down loses nothing but the chance to also\n // push down what follows it, which is a limit over ten rows.\n this.nextExecutionTarget = \"memory\";\n }\n\n if (name === \"join\") {\n // Everything AFTER a join runs in memory, for the same reason as `nearest`: this\n // collection cannot see HOW the plugin executed the join, and the rows it produced\n // are TUPLES rather than entities of the root schema.\n //\n // A `take` sent to a backend that hash-joined in its translator would limit the\n // OUTER rows read, not the pairs produced — a plausible-looking result with the\n // wrong number of rows in it. Conjuncts that can safely run earlier are split off\n // by the query builder BEFORE dispatch, which is the only exception.\n this.nextExecutionTarget = \"memory\";\n }\n }\n\n /**\n * Splits the collection around the FIRST occurrence of `name`, preserving order.\n *\n * For a join: the options recorded before it operate on entity rows, the option itself\n * produces tuples, and the ones after it operate on tuples. Three different shapes, so the\n * caller has to run them in three steps rather than one pass.\n */\n splitAt<K extends QueryOptionName>(name: K): { before: QueryOptionsCollection<T>, at: QueryOption<T, K> | null, after: QueryOptionsCollection<T> } {\n this.resolveEnumeration();\n\n const sortedItems = this.enumeratedItems.toSorted((a, b) => a.index - b.index);\n const before = new QueryOptionsCollection<T>();\n const after = new QueryOptionsCollection<T>();\n let at: QueryOption<T, K> | null = null;\n\n for (let i = 0, length = sortedItems.length; i < length; i++) {\n const { option } = sortedItems[i];\n\n if (at == null && option.name === name) {\n at = option as QueryOption<T, K>;\n continue;\n }\n\n const destination = at == null ? before : after;\n destination.add(option.name, option.value);\n }\n\n return { before, at, after };\n }\n\n /**\n * Captures the collection's current state and returns a function that restores it.\n *\n * Terminal queryable operations (count, first, aggregates, …) record their option on\n * the shared collection before executing. Without restoring, a re-executed terminal —\n * the whole point of a subscribed queryable — stacks its option a second time and\n * runs it over the first execution's scalar result.\n */\n snapshot(): () => void {\n const options = new Map([...this.options.entries()].map(([key, items]): [QueryOptionName, QueryCollectionItem<any, any>[]] => [key, [...items]]));\n const nextExecutionTarget = this.nextExecutionTarget;\n const nextIndex = this.nextIndex;\n\n return () => {\n this.options = new Map(options);\n this.nextExecutionTarget = nextExecutionTarget;\n this.nextIndex = nextIndex;\n this.enumeratedItems = [];\n };\n }\n\n split(): { memory: QueryOptionsCollection<T>, database: QueryOptionsCollection<T> } {\n this.resolveEnumeration();\n\n const sortedItems = this.enumeratedItems.toSorted((a, b) => a.index - b.index);\n const memoryQueryOptionsCollection = new QueryOptionsCollection<T>();\n const databaseQueryOptionsCollection = new QueryOptionsCollection<T>();\n\n for (let i = 0, length = sortedItems.length; i < length; i++) {\n const sortedItem = sortedItems[i];\n\n if (sortedItem.option.target === \"database\") {\n databaseQueryOptionsCollection.add(sortedItem.option.name, sortedItem.option.value);\n continue;\n }\n\n memoryQueryOptionsCollection.add(sortedItem.option.name, sortedItem.option.value);\n }\n\n return {\n memory: memoryQueryOptionsCollection,\n database: databaseQueryOptionsCollection\n }\n }\n\n hasTransformations(): boolean {\n const transformationOptions: QueryOptionName[] = [\"map\", \"group\", \"min\", \"max\", \"count\", \"sum\"];\n return transformationOptions.some((name) => this.options.has(name));\n }\n\n has<K extends QueryOptionName>(name: K): boolean {\n return this.options.has(name);\n }\n\n get<K extends QueryOptionName>(name: K): QueryCollectionItem<T, K>[] {\n return this.options.get(name) ?? [] as QueryCollectionItem<T, K>[];\n }\n\n getLast<K extends QueryOptionName>(name: K): QueryOption<T, K> | null {\n this.resolveEnumeration();\n\n for (let i = this.enumeratedItems.length - 1; i >= 0; i--) {\n const item = this.enumeratedItems[i];\n\n if (item.option.name === name) {\n return item.option;\n }\n }\n\n return null\n }\n\n getValues<K extends QueryOptionName>(name: K): QueryCollectionItem<T, K>[\"option\"][\"value\"][] | undefined {\n\n const found = this.options.get(name);\n\n if (found == null) {\n return [];\n }\n\n return found.map(w => w.option.value) as QueryCollectionItem<T, K>[\"option\"][\"value\"][];\n }\n\n private getEnumeration() {\n return [...this.options.values()].flat().toSorted((a, b) => a.index - b.index);\n }\n\n private resolveEnumeration() {\n if (this.enumeratedItems.length != this.nextIndex) {\n this.enumeratedItems = this.getEnumeration();\n }\n }\n\n forEach(iterator: (item: QueryCollectionItem<T, any>[\"option\"]) => void) {\n this.resolveEnumeration();\n\n for (let i = 0, length = this.enumeratedItems.length; i < length; i++) {\n iterator(this.enumeratedItems[i].option);\n }\n }\n}","export const isDate = (data: unknown): data is Date => {\n if (data == null) {\n return false;\n }\n\n if (typeof data !== \"object\") {\n return false;\n }\n\n return data instanceof Date;\n}","/**\n * Levelled logging, resolved once.\n *\n * Three things about the previous implementation drove this shape:\n *\n * - **There was no way to turn logging off.** `globalThis.__ROUTIER_DEBUG__` was only ever\n * compared against `true`, so setting it to `false` did nothing — while\n * `docs/how-to/debug-logging.md` documented exactly that as the way to force logging off.\n * A documented switch that silently does nothing is worse than no switch.\n * - **`NODE_ENV === 'test'` enabled it.** Every Jest run therefore logged, because Jest always\n * sets `NODE_ENV=test`. Measured on the S7 stress scenario, which drives ~2,000 saves through\n * a plugin that logs three lines per query: 12.4s with logging, ~6s without. Test runners also\n * capture console output by snapshotting a stack trace per call, so the cost is far above what\n * writing to a terminal would suggest — and the output buries whatever the failure was.\n * - **It was all-or-nothing, and re-resolved per call.** An error could not be kept while debug\n * was dropped, and every one of the ~97 call sites re-read `globalThis` and `process.env`.\n *\n * Levels are compared numerically against a value cached at module load. Measured against a\n * no-op console at 200k calls: an enabled call costs ~70ns, a call rejected by the gate ~3ns.\n * Building the arguments the call site passes in accounts for ~0.2ns of that 3ns, which is why\n * this keeps the ordinary `logger.debug(msg, payload)` signature instead of taking a thunk —\n * a lazy API would recover 0.3% of an enabled call's cost and would have to change every call\n * site to do it.\n */\n\n/** Ordered from most severe to most verbose. `silent` discards everything. */\nexport const LOG_LEVELS = ['silent', 'error', 'warn', 'info', 'debug'] as const;\n\nexport type LogLevel = (typeof LOG_LEVELS)[number];\n\n/** Numeric rank, so a gate is one integer comparison. */\nconst RANK: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n};\n\nconst isLogLevel = (value: unknown): value is LogLevel =>\n typeof value === 'string' && (LOG_LEVELS as readonly string[]).includes(value);\n\n/**\n * Resolves the configured level, in precedence order.\n *\n * Ordered most specific first: an explicit level beats a boolean flag, a boolean flag beats an\n * environment variable, and an environment variable beats an inference from `NODE_ENV`. Anything\n * unrecognised is ignored rather than treated as an error — a typo'd level should not take down\n * an application, and `silent` is the safe direction to fall back to.\n */\nconst resolveLevel = (): LogLevel => {\n if (typeof globalThis !== 'undefined') {\n const g = globalThis as { __ROUTIER_LOG_LEVEL__?: unknown; __ROUTIER_DEBUG__?: unknown };\n\n if (isLogLevel(g.__ROUTIER_LOG_LEVEL__)) {\n return g.__ROUTIER_LOG_LEVEL__;\n }\n\n // Both directions honoured. `=== false` used to fall through to the NODE_ENV checks\n // below and re-enable the logging it was asked to suppress.\n if (g.__ROUTIER_DEBUG__ === true) return 'debug';\n if (g.__ROUTIER_DEBUG__ === false) return 'silent';\n }\n\n // There is deliberately no `import.meta.env` branch, although the documentation used to\n // promise one. It could never work: this package is bundled with rspack, which replaces\n // `import.meta` with `undefined`, so the check would read the *library's* build-time\n // environment rather than the application's — and referencing `import.meta` at all is a parse\n // error under a CommonJS build target, which is how the test suite loads this file. Vite and\n // similar apps set `__ROUTIER_LOG_LEVEL__` or `__ROUTIER_DEBUG__` from their own\n // `import.meta.env`, which is what the docs now describe.\n if (typeof process !== 'undefined' && process.env != null) {\n if (isLogLevel(process.env.ROUTIER_LOG_LEVEL)) {\n return process.env.ROUTIER_LOG_LEVEL as LogLevel;\n }\n\n const debug = process.env.DEBUG;\n if (debug === 'routier' || debug === '*') return 'debug';\n\n const env = process.env.NODE_ENV?.toLowerCase();\n\n // `test` is deliberately absent. It used to be here, which meant no test suite anywhere\n // could run Routier quietly. Opt in with DEBUG=routier or ROUTIER_LOG_LEVEL when a test\n // needs the output.\n if (env === 'dev' || env === 'development') return 'debug';\n }\n\n return 'silent';\n};\n\nlet level: LogLevel = resolveLevel();\nlet rank = RANK[level];\n\n/**\n * Overrides the level for the rest of the process.\n *\n * The configuration above is read once, at import, which is what makes the gate cheap — but it\n * also means an application that decides its verbosity after startup, or a test that wants to\n * assert on output, has no way in. This is that way in.\n */\nexport const setLogLevel = (next: LogLevel): void => {\n if (isLogLevel(next) === false) {\n throw new Error(`Unknown log level \"${next}\". Expected one of: ${LOG_LEVELS.join(', ')}`);\n }\n\n level = next;\n rank = RANK[next];\n};\n\nexport const getLogLevel = (): LogLevel => level;\n\n/** Re-reads the environment. For tests that change it after this module was imported. */\nexport const resetLogLevel = (): void => {\n level = resolveLevel();\n rank = RANK[level];\n};\n\n/**\n * Whether a message at this level would be emitted.\n *\n * For the rare call site whose *arguments* are expensive to build — a serialization, a deep\n * clone, a join over a large collection. An ordinary payload object is not worth guarding; see\n * the measurement in the header.\n */\nexport const isLogLevelEnabled = (at: LogLevel): boolean => rank >= RANK[at];\n\ntype ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'debug' | 'table';\n\nconst emit = (at: LogLevel, method: ConsoleMethod, args: unknown[]) => {\n if (rank < RANK[at]) {\n return;\n }\n\n // Resolved at call time rather than captured once: test harnesses and browser devtools both\n // replace console methods after modules have loaded, and a captured reference would keep\n // writing past the replacement.\n (console[method] as (...a: unknown[]) => void)(...args);\n};\n\nexport const logger = {\n /** General-purpose output. Carried at `info`, since `log` names a console method, not a level. */\n log: (...args: unknown[]): void => emit('info', 'log', args),\n info: (...args: unknown[]): void => emit('info', 'info', args),\n warn: (...args: unknown[]): void => emit('warn', 'warn', args),\n error: (...args: unknown[]): void => emit('error', 'error', args),\n debug: (...args: unknown[]): void => emit('debug', 'debug', args),\n /** Diagnostic tabular output; verbose by nature, so it sits at `debug`. */\n table: (...args: unknown[]): void => emit('debug', 'table', args),\n};\n","export const hash = (value: string, seed: number = 0) => {\n // From Stack Overflow\n // https://stackoverflow.com/a/52171480/3329760\n let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;\n\n for (let i = 0, ch: number; i < value.length; i++) {\n ch = value.charCodeAt(i);\n h1 = Math.imul(h1 ^ ch, 2654435761);\n h2 = Math.imul(h2 ^ ch, 1597334677);\n }\n\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);\n h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);\n h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n\n return 4294967296 * (2097151 & h2) + (h1 >>> 0);\n}\n\n/**\n * Fast string hash optimized for comparisons.\n * Uses djb2 algorithm - very fast and good distribution for short to medium strings.\n * Same input always produces same output (deterministic).\n * \n * @param value - The string to hash\n * @param seed - Optional seed value (default: 5381)\n * @returns A positive 32-bit integer hash value\n * \n * @example\n * ```ts\n * fastHash(\"test\") === fastHash(\"test\") // true\n * fastHash(\"test\") !== fastHash(\"test2\") // true\n * ```\n */\nexport const fastHash = (value: string, seed: number = 5381): number => {\n let hash = seed;\n for (let i = 0; i < value.length; i++) {\n hash = ((hash << 5) + hash) + value.charCodeAt(i);\n }\n return hash >>> 0; // Convert to unsigned 32-bit integer\n}\n\n/**\n * Converts any value to a readable string representation.\n * Handles primitives, objects, arrays, classes, dates, errors, and functions.\n * Supports depth limiting to prevent infinite recursion on circular references.\n * \n * @param obj - The value to stringify\n * @param maxDepth - Maximum depth for nested objects (default: 3)\n * @param currentDepth - Current recursion depth (default: 0)\n * @returns String representation of the value\n * \n * @example\n * ```ts\n * stringifyObject({ name: \"test\", count: 5 }) // '{ name: \"test\", count: 5 }'\n * stringifyObject([1, 2, 3]) // '[1, 2, 3]'\n * stringifyObject(new Date()) // 'Date(2024-01-01T00:00:00.000Z)'\n * ```\n */\nexport function stringifyObject(obj: unknown, maxDepth: number = 3, currentDepth: number = 0): string {\n if (obj === null) return 'null';\n if (obj === undefined) return 'undefined';\n\n const type = typeof obj;\n\n switch (type) {\n case 'string':\n return `\"${obj}\"`;\n case 'number':\n case 'boolean':\n return String(obj);\n case 'function':\n return `[Function: ${getFunctionName(obj as Function)}]`;\n case 'object':\n if (currentDepth >= maxDepth) {\n return '[Max Depth Reached]';\n }\n return stringifyObjectValue(obj, maxDepth, currentDepth);\n default:\n return `[${type}]`;\n }\n}\n\nfunction getFunctionName(fn: Function): string {\n const name = fn.name;\n return name || 'anonymous';\n}\n\nfunction getObjectProperties(obj: any): Record<string, any> {\n const properties: Record<string, any> = {};\n\n for (const key in obj) {\n if (obj.hasOwnProperty(key)) {\n properties[key] = obj[key];\n }\n }\n\n return properties;\n}\n\nfunction stringifyObjectValue(obj: any, maxDepth: number, currentDepth: number): string {\n if (obj === null) return 'null';\n\n if (obj instanceof Date) {\n return `Date(${obj.toISOString()})`;\n }\n\n if (obj instanceof Error) {\n return `Error(${obj.message})`;\n }\n\n if (obj instanceof RegExp) {\n return obj.toString();\n }\n\n if (Array.isArray(obj)) {\n return stringifyArray(obj, maxDepth, currentDepth);\n }\n\n if (obj.constructor && obj.constructor.name !== 'Object') {\n return stringifyClassInstance(obj, maxDepth, currentDepth);\n }\n\n return stringifyPlainObject(obj, maxDepth, currentDepth);\n}\n\nfunction stringifyArray(arr: any[], maxDepth: number, currentDepth: number): string {\n if (arr.length === 0) return '[]';\n\n const items = arr.slice(0, 5).map(item =>\n stringifyObject(item, maxDepth, currentDepth + 1)\n );\n\n const suffix = arr.length > 5 ? `... (+${arr.length - 5} more)` : '';\n return `[${items.join(', ')}${suffix}]`;\n}\n\nfunction stringifyClassInstance(obj: any, maxDepth: number, currentDepth: number): string {\n const className = obj.constructor.name;\n const properties = getObjectProperties(obj);\n\n if (Object.keys(properties).length === 0) {\n return `${className} {}`;\n }\n\n const props = Object.entries(properties)\n .slice(0, 5)\n .map(([key, value]) => {\n const isPrimitive = value === null || value === undefined ||\n (typeof value !== 'object' && typeof value !== 'function');\n const depth = isPrimitive ? currentDepth : currentDepth + 1;\n return `${key}: ${stringifyObject(value, maxDepth, depth)}`;\n });\n\n const suffix = Object.keys(properties).length > 5 ?\n `... (+${Object.keys(properties).length - 5} more)` : '';\n\n return `${className} { ${props.join(', ')}${suffix} }`;\n}\n\nfunction stringifyPlainObject(obj: any, maxDepth: number, currentDepth: number): string {\n const properties = getObjectProperties(obj);\n\n if (Object.keys(properties).length === 0) {\n return '{}';\n }\n\n const props = Object.entries(properties)\n .slice(0, 5)\n .map(([key, value]) => {\n const isPrimitive = value === null || value === undefined ||\n (typeof value !== 'object' && typeof value !== 'function');\n const depth = isPrimitive ? currentDepth : currentDepth + 1;\n return `${key}: ${stringifyObject(value, maxDepth, depth)}`;\n });\n\n const suffix = Object.keys(properties).length > 5 ?\n `... (+${Object.keys(properties).length - 5} more)` : '';\n\n return `{ ${props.join(', ')}${suffix} }`;\n}","export const uuid = (length: number = 16): string => {\n const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n const charLength = chars.length;\n let result = '';\n\n for (let i = 0; i < length; i++) {\n result += chars[Math.random() * charLength | 0];\n }\n return result;\n}\n\nconst HEX_CHARS = '0123456789abcdef';\nconst UUID_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';\n\nconst hasCrypto =\n typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function';\n\nconst hasRandomUUID =\n typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function';\n\nexport const uuidv4 = (): string => {\n if (hasRandomUUID) {\n return crypto.randomUUID();\n }\n\n return uuidv4Fallback();\n};\n\nconst uuidv4Fallback = (): string => {\n let randomBytes: Uint8Array | null = null;\n if (hasCrypto) {\n randomBytes = crypto.getRandomValues(new Uint8Array(16));\n }\n\n let byteIndex = 0;\n let uuid = '';\n\n for (let i = 0; i < UUID_TEMPLATE.length; i++) {\n const c = UUID_TEMPLATE[i];\n if (c === '-') {\n uuid += '-';\n continue;\n }\n\n let r: number;\n if (hasCrypto && randomBytes) {\n // Each byte gives two hex digits (nibbles)\n r =\n (i % 2 === 0\n ? randomBytes[byteIndex] >> 4\n : randomBytes[byteIndex++] & 0x0f);\n } else {\n r = Math.floor(Math.random() * 16);\n }\n\n if (c === 'x') {\n uuid += HEX_CHARS[r];\n } else if (c === 'y') {\n // Variant bits: 8, 9, A, or B\n uuid += HEX_CHARS[(r & 0x3) | 0x8];\n } else if (c === '4') {\n uuid += '4';\n }\n }\n\n return uuid;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export const toMap = <T extends {}>(data: T[], keySelector: (item: T) => T[keyof T] | string) => {\n\n const result = new Map<T[keyof T] | string, T>();\n\n for (let i = 0; i < data.length; i++) {\n const item = data[i];\n const key = keySelector(item);\n result.set(key, item);\n }\n\n return result;\n}\n","export const cast = <TIn, TOut>(item: TIn) => {\n return item as unknown as TOut;\n}\n\nexport function clone<T extends {}>(data: T): T {\n return JSON.parse(JSON.stringify(data)) as T;\n}","export const isNodeRuntime = () => typeof process !== 'undefined' &&\n process.versions != null &&\n process.versions.node != null;","import { BulkPersistResult, BulkPersistChanges } from \"../collections\";\nimport { DbPluginBulkPersistEvent } from \"../plugins\";\n\nexport const resolveBulkPersistChanges = (event: DbPluginBulkPersistEvent, result: BulkPersistResult, bulkPersistChanges: BulkPersistChanges) => {\n // make sure we swap the adds here, that way we can make sure other persist events\n // don't take their additions and try to change subsequent calls\n for (const [schemaId, changes] of event.operation) {\n\n const schemmaBulkPersistResult = result.get(schemaId);\n const schemaBulkPersistChanges = bulkPersistChanges.resolve(schemaId);\n\n // Set the original removes\n schemaBulkPersistChanges.removes = changes.removes;\n\n // Set the original updates\n schemaBulkPersistChanges.updates = changes.updates;\n\n // Take the adds from the result and set them to be persisted\n // in the replicated plugins because the id's are set in the \n // memory data store\n schemaBulkPersistChanges.adds = schemmaBulkPersistResult.adds;\n }\n}","import { QueryOptionsCollection } from \"../plugins/query\";\n\nexport const combineQueryOptionsCollections = <T>(...collections: QueryOptionsCollection<T>[]) => {\n const result = new QueryOptionsCollection<T>();\n\n for (let i = 0, length = collections.length; i < length; i++) {\n const collection = collections[i];\n\n // Add scoped items first\n collection.forEach(item => {\n result.add(item.name, item.value);\n });\n }\n\n return result;\n}","import { InferCreateType, InferType, SchemaId } from \"../schema\";\nimport { DbPluginBulkPersistEvent, EntityUpdateInfo } from \"../plugins\";\n\ntype DbEvent = {\n type: \"add\",\n data: InferCreateType<unknown>;\n} | {\n type: \"update\",\n data: EntityUpdateInfo<unknown>;\n} | {\n type: \"remove\",\n data: InferType<unknown>;\n}\n\nexport const toEventArray = (event: DbPluginBulkPersistEvent): [SchemaId, DbEvent][] => {\n\n const result: [SchemaId, DbEvent][] = [];\n for (const [schemaId, changes] of event.operation) {\n\n if (changes.hasItems === false) {\n continue;\n }\n\n if (changes.adds.length > 0) {\n result.push(...changes.adds.map(add => {\n return [schemaId as SchemaId, { data: { ...add }, type: \"add\" }] as [SchemaId, DbEvent];\n }));\n }\n\n if (changes.updates.length > 0) {\n result.push(...changes.updates.map(update => {\n return [schemaId as SchemaId, { data: { ...update }, type: \"update\" }] as [SchemaId, DbEvent];\n }));\n }\n\n if (changes.removes.length > 0) {\n result.push(...changes.removes.map(remove => {\n return [schemaId as SchemaId, { data: { ...remove }, type: \"remove\" }] as [SchemaId, DbEvent];\n }));\n }\n }\n\n return result\n}","export const noop = (..._args: any[]) => { };","export const unsafeCast = <T>(value: unknown): T => {\n return value as T\n}","export * from './arrays';\nexport * from './strings';\nexport * from './dates';\nexport * from './objects';\nexport * from './runtime';\nexport * from './uuid';\nexport * from './replication';\nexport * from './types';\nexport * from './queryOptionsCollection';\nexport * from './dbPluginEventUtils';\nexport * from './functions';\nexport * from './unsafeCast';\nexport * from './logger';"],"names":["EXPRESSION_TYPES","isDate","assertDate","data","TypeError","assertIsNotNull","message","assertIsArray","Array","assertString","assertInstanceOf","value","Instance","assertIsNumber","isObjectWithType","isExpression","isOperatorExpression","isComparatorExpression","isPropertyExpression","isValueExpression","isEmptyExpression","isNotParsableExpression","getProperties","expression","properties","traverse","expr","forEach","callback","QueryOptionsCollection","Map","options","name","mapValue","x","filterValue","sortValue","nearestValue","joinValue","item","found","sortedItems","a","b","before","after","at","i","length","option","destination","key","items","nextExecutionTarget","nextIndex","memoryQueryOptionsCollection","databaseQueryOptionsCollection","sortedItem","transformationOptions","w","iterator","Date","LOG_LEVELS","RANK","isLogLevel","resolveLevel","globalThis","g","process","debug","env","level","rank","setLogLevel","next","Error","getLogLevel","resetLogLevel","isLogLevelEnabled","emit","method","args","console","logger","hash","seed","h1","h2","ch","Math","fastHash","stringifyObject","obj","maxDepth","currentDepth","undefined","type","String","getFunctionName","stringifyObjectValue","fn","getObjectProperties","RegExp","stringifyArray","stringifyClassInstance","stringifyPlainObject","arr","suffix","className","Object","props","isPrimitive","depth","uuid","chars","charLength","result","HEX_CHARS","UUID_TEMPLATE","hasCrypto","crypto","hasRandomUUID","uuidv4","uuidv4Fallback","randomBytes","Uint8Array","byteIndex","c","r","toMap","keySelector","cast","clone","JSON","isNodeRuntime","resolveBulkPersistChanges","event","bulkPersistChanges","schemaId","changes","schemmaBulkPersistResult","schemaBulkPersistChanges","combineQueryOptionsCollections","collections","collection","toEventArray","add","update","remove","noop","_args","unsafeCast"],"mappings":";;;;;;;AAA4D;AAEtB;AAE/B,SAASE,WAAWC,IAAa;IACpC,IAAIF,OAAOE,UAAU,OAAO;QACxB,MAAM,IAAIC,UAAU;IACxB;AACJ;AAEO,SAASC,gBAAmBF,IAA0B,EAAEG,OAAiC;IAC5F,IAAIH,QAAQ,MAAM;QACd,IAAIG,WAAW,MAAM;YACjB,MAAM,IAAIF,UAAU;QACxB;QAEA,IAAI,OAAOE,YAAY,UAAU;YAC7B,MAAM,IAAIF,UAAUE;QACxB;QAEA,MAAM,IAAIF,UAAUE;IACxB;AACJ;AAEO,SAASC,cAAiBJ,IAAa,EAAEG,OAAgB;IAC5D,IAAI,CAACE,MAAM,OAAO,CAACL,OAAO;QACtB,MAAM,IAAIC,UAAUE,WAAW;IACnC;AACJ;AAEO,SAASG,aAAaN,IAAa,EAAEG,OAAgB;IACxD,IAAI,OAAOH,SAAS,UAAU;QAC1B,MAAM,IAAIC,UAAUE,WAAW;IACnC;AACJ;AAEO,SAASI,iBAAwDC,KAAc,EAAEC,QAAW;IAC/F,IAAID,iBAAiBC,UAAU;QAC3B;IACJ;IAEA,IAAID,SAAS,QAAQ,OAAOA,UAAU,YAAY,iBAAiBA,OAAO;QACtE,MAAM,IAAIP,UAAU,CAAC,sCAAsC,EAAEO,MAAM,WAAW,CAAC,IAAI,EAAE;IACzF;IAEA,MAAM,IAAI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Q,QAAQ,KAAK,OAAO;YAC5B;QACJ;QAEA,IAAIA,QAAQ,IAAI,CAAC,MAAM,GAAG,GAAG;YACzBvB,OAAO,IAAI,IAAIuB,QAAQ,IAAI,CAAC,GAAG,CAACO,CAAAA;gBAC5B,OAAO;oBAACR;oBAAsB;wBAAE,MAAM;4BAAE,GAAGQ,GAAG;wBAAC;wBAAG,MAAM;oBAAM;iBAAE;YACpE;QACJ;QAEA,IAAIP,QAAQ,OAAO,CAAC,MAAM,GAAG,GAAG;YAC5BvB,OAAO,IAAI,IAAIuB,QAAQ,OAAO,CAAC,GAAG,CAACQ,CAAAA;gBAC/B,OAAO;oBAACT;oBAAsB;wBAAE,MAAM;4BAAE,GAAGS,MAAM;wBAAC;wBAAG,MAAM;oBAAS;iBAAE;YAC1E;QACJ;QAEA,IAAIR,QAAQ,OAAO,CAAC,MAAM,GAAG,GAAG;YAC5BvB,OAAO,IAAI,IAAIuB,QAAQ,OAAO,CAAC,GAAG,CAACS,CAAAA;gBAC/B,OAAO;oBAACV;oBAAsB;wBAAE,MAAM;4BAAE,GAAGU,MAAM;wBAAC;wBAAG,MAAM;oBAAS;iBAAE;YAC1E;QACJ;IACJ;IAEA,OAAOhC;AACX,EAAC;;;AC3CM,MAAMiC,OAAO,CAAC,GAAGC,SAAmB,EAAE;;;ACAtC,MAAMC,aAAa,CAAI5I;IAC1B,OAAOA;AACX,EAAC;;;;;ACFwB;AACC;AACF;AACE;AACA;AACH;AACO;AACN;AACiB;AACJ;AACT;AACC;AACJ"}
|
|
1
|
+
{"version":3,"file":"utilities/index.cjs","sources":["webpack://@routier/core/./src/assertions/index.ts","webpack://@routier/core/./src/expressions/utils.ts","webpack://@routier/core/./src/plugins/query/QueryOptionsCollection.ts","webpack://@routier/core/./src/utilities/dates.ts","webpack://@routier/core/./src/utilities/logger.ts","webpack://@routier/core/./src/utilities/strings.ts","webpack://@routier/core/./src/utilities/uuid.ts","webpack://@routier/core/webpack/runtime/define_property_getters","webpack://@routier/core/webpack/runtime/has_own_property","webpack://@routier/core/webpack/runtime/make_namespace_object","webpack://@routier/core/./src/utilities/arrays.ts","webpack://@routier/core/./src/utilities/objects.ts","webpack://@routier/core/./src/utilities/runtime.ts","webpack://@routier/core/./src/utilities/replication.ts","webpack://@routier/core/./src/utilities/queryOptionsCollection.ts","webpack://@routier/core/./src/utilities/dbPluginEventUtils.ts","webpack://@routier/core/./src/utilities/functions.ts","webpack://@routier/core/./src/utilities/unsafeCast.ts","webpack://@routier/core/./src/utilities/index.ts"],"sourcesContent":["import { EXPRESSION_TYPES } from \"../expressions/constants\";\nimport { ComparatorExpression, EmptyExpression, Expression, ExpressionType, NotParsableExpression, OperatorExpression, PropertyExpression, ValueExpression } from \"../expressions/types\";\nimport { isDate } from \"../utilities\";\n\nexport function assertDate(data: unknown): asserts data is Date {\n if (isDate(data) === false) {\n throw new TypeError('Value is not a Date');\n }\n}\n\nexport function assertIsNotNull<T>(data: T | null | undefined, message?: string | (() => string)): asserts data is NonNullable<T> {\n if (data == null) {\n if (message == null) {\n throw new TypeError('Assertion failed, data is null');\n }\n\n if (typeof message === \"string\") {\n throw new TypeError(message);\n }\n\n throw new TypeError(message());\n }\n}\n\nexport function assertIsArray<T>(data: unknown, message?: string): asserts data is T[] {\n if (!Array.isArray(data)) {\n throw new TypeError(message ?? 'Assertion failed, data is not of type Array');\n }\n}\n\nexport function assertString(data: unknown, message?: string): asserts data is string {\n if (typeof data !== \"string\") {\n throw new TypeError(message ?? 'Assertion failed, data is not of type String');\n }\n}\n\nexport function assertInstanceOf<T extends new (...args: any[]) => any>(value: unknown, Instance: T): asserts value is T {\n if (value instanceof Instance) {\n return;\n }\n\n if (value != null && typeof value === \"object\" && \"constructor\" in value) {\n throw new TypeError(`value is not instance of type. Type: ${value.constructor.name}`);\n }\n\n throw new TypeError(`value is not instance of type`);\n}\n\nexport function assertIsNumber(value: unknown): asserts value is number {\n if (typeof value !== \"number\") {\n throw new TypeError(\"value is not of type `number`\");\n }\n}\n\n\nfunction isObjectWithType(value: unknown): value is Record<\"type\", unknown> {\n return typeof value === \"object\" && value !== null && \"type\" in value;\n}\n\n/**\n * Type guard: narrows `value` to `Expression` when it is an object with a valid `type` property.\n */\nexport function isExpression(value: unknown): value is Expression {\n return isObjectWithType(value) && EXPRESSION_TYPES.includes(value.type as ExpressionType);\n}\n\n/**\n * Type guard: narrows `value` to `OperatorExpression` when it is an object with `type === \"operator\"`.\n */\nexport function isOperatorExpression(value: unknown): value is OperatorExpression {\n return isObjectWithType(value) && value.type === \"operator\";\n}\n\n/**\n * Type guard: narrows `value` to `ComparatorExpression` when it is an object with `type === \"comparator\"`.\n */\nexport function isComparatorExpression(value: unknown): value is ComparatorExpression {\n return isObjectWithType(value) && value.type === \"comparator\";\n}\n\n/**\n * Type guard: narrows `value` to `PropertyExpression` when it is an object with `type === \"property\"`.\n */\nexport function isPropertyExpression(value: unknown): value is PropertyExpression {\n return isObjectWithType(value) && value.type === \"property\";\n}\n\n/**\n * Type guard: narrows `value` to `ValueExpression` when it is an object with `type === \"value\"`.\n */\nexport function isValueExpression(value: unknown): value is ValueExpression {\n return isObjectWithType(value) && value.type === \"value\";\n}\n\n/**\n * Type guard: narrows `value` to `EmptyExpression` when it is an object with `type === \"empty\"`.\n */\nexport function isEmptyExpression(value: unknown): value is EmptyExpression {\n return isObjectWithType(value) && value.type === \"empty\";\n}\n\n/**\n * Type guard: narrows `value` to `NotParsableExpression` when it is an object with `type === \"not-parsable\"`.\n */\nexport function isNotParsableExpression(value: unknown): value is NotParsableExpression {\n return isObjectWithType(value) && value.type === \"not-parsable\";\n}","import { PropertyInfo } from \"../schema\";\nimport { Expression, PropertyExpression } from \"./types\";\n\n/**\n * Extracts all properties referenced in an expression\n * @param expression The expression to analyze\n * @returns Array of PropertyInfo objects referenced in the expression\n */\nexport function getProperties(expression: Expression): PropertyInfo<any>[] {\n const properties: PropertyInfo<any>[] = [];\n\n function traverse(expr: Expression) {\n // If this is a property expression, add it to our collection\n if (expr.type === \"property\") {\n properties.push((expr as PropertyExpression).property);\n }\n\n // Traverse left and right expressions if they exist\n if (expr.left) {\n traverse(expr.left);\n }\n if (expr.right) {\n traverse(expr.right);\n }\n }\n\n traverse(expression);\n return properties;\n}\n\nexport function forEach(expression: Expression, callback: (expression: Expression) => boolean) {\n function traverse(expr: Expression): boolean {\n // Call the callback for this expression\n // If callback returns false, stop traversing\n if (!callback(expr)) {\n return false;\n }\n\n // Traverse left and right expressions if they exist\n if (expr.left) {\n if (!traverse(expr.left)) {\n return false;\n }\n }\n if (expr.right) {\n if (!traverse(expr.right)) {\n return false;\n }\n }\n\n return true;\n }\n\n traverse(expression);\n}","import { isPropertyExpression } from \"../../assertions\";\nimport { forEach } from \"../../expressions/utils\";\nimport { MemoryExecutionReason, QueryOption, QueryOptionName, QueryOptionExecutionTarget, QueryOptionValueMap } from \"./types\";\n\nexport type QueryCollectionItem<T, K extends QueryOptionName> = { index: number, option: QueryOption<T, K> };\n\nexport class QueryOptionsCollection<T> {\n\n private options: Map<QueryOptionName, QueryCollectionItem<any, any>[]> = new Map<QueryOptionName, QueryCollectionItem<any, any>[]>();\n private nextExecutionTarget: QueryOptionExecutionTarget = \"database\";\n private nextExecutionReason: MemoryExecutionReason | null = null;\n private nextIndex: number = 0;\n private enumeratedItems: QueryCollectionItem<any, any>[] = [];\n\n /** Cuts over to memory execution, keeping the first cause. See `MemoryExecutionReason`. */\n private cutOverToMemory(reason: MemoryExecutionReason) {\n this.nextExecutionTarget = \"memory\";\n\n if (this.nextExecutionReason == null) {\n this.nextExecutionReason = reason;\n }\n }\n\n /**\n * True when `split()` or `splitAt()` produced this collection.\n *\n * Those rebuild each half by re-adding its options, which re-derives execution targets\n * without the options that caused them — a post-join filter alone in the memory half\n * derives back to `\"database\"`. Anything reading `target` as a report of where work runs\n * has to reject a derived collection; see `explainQuery`.\n */\n private derived: boolean = false;\n\n get isDerived() {\n return this.derived;\n }\n\n get items() {\n return this.options;\n }\n\n get isEmpty() {\n return this.items.size === 0;\n }\n\n static EMPTY<R>() {\n return new QueryOptionsCollection<R>();\n }\n\n static isEmpty<T>(options: QueryOptionsCollection<T>) {\n return options.isEmpty;\n }\n\n add<K extends QueryOptionName>(name: K, value: QueryOption<T, K>[\"value\"]) {\n\n if (name === \"map\") {\n const mapValue = value as QueryOptionValueMap<T>[\"map\"];\n\n // Evaluate the map value to see if we are renaming properties, \n // if we are we need to perform everything after in memory\n if (mapValue.fields.some(x => x.isRename === true) || mapValue.fields.some(x => x.property?.isUnmapped === true)) {\n // Cut over to memory execution since we are renaming a property with .map\n // We do not want to figure out how the new name flows through the entire query\n this.cutOverToMemory(\"map-rename\");\n }\n }\n\n if (name === \"filter\") {\n // Need to check for unmapped and renamed properties\n const filterValue = value as QueryOptionValueMap<T>[\"filter\"];\n\n // A tautology (`x => true`) filters nothing — skip it entirely so\n // plugins never see it\n if (filterValue.expression.type === \"empty\") {\n return;\n }\n\n if (filterValue.expression.type === \"not-parsable\") {\n this.cutOverToMemory(\"not-parsable\");\n } else {\n forEach(filterValue.expression, (expression) => {\n\n if (isPropertyExpression(expression) && expression.property.isUnmapped) {\n // Cut over to memory execution, unmapped properties are not in the database and\n // cannot be queried\n this.cutOverToMemory(\"unmapped-property\");\n return false;\n }\n\n if (isPropertyExpression(expression) && expression.property.hasRenamedSegments) {\n // Cut over to memory execution: the plugin stores data under the\n // `from` (storage) names, but filter selectors reference the\n // in-memory names. Memory execution runs after deserialization,\n // where the in-memory names exist\n this.cutOverToMemory(\"renamed-property\");\n return false;\n }\n\n return true;\n });\n }\n }\n\n if (name === \"sort\") {\n const sortValue = value as QueryOptionValueMap<T>[\"sort\"];\n\n // Same rule as filters: sort selectors reference in-memory names, which\n // only exist after deserialization when the property is renamed or unmapped\n if (sortValue.property != null && sortValue.property.isUnmapped) {\n this.cutOverToMemory(\"unmapped-property\");\n } else if (sortValue.property != null && sortValue.property.hasRenamedSegments) {\n this.cutOverToMemory(\"renamed-property\");\n }\n }\n\n if (name === \"nearest\") {\n const nearestValue = value as QueryOptionValueMap<T>[\"nearest\"];\n\n // Same rule as sort, and for the same reason: the plugin stores the vector under\n // the `from` name, and an unmapped property is not stored at all. Both are only\n // readable after deserialization, which is where memory execution runs.\n //\n // This is also what lets every translator's in-memory fallback read the column by\n // its resolved name — anything whose storage name differs never reaches them.\n if (nearestValue.property != null && nearestValue.property.isUnmapped) {\n this.cutOverToMemory(\"unmapped-property\");\n } else if (nearestValue.property != null && nearestValue.property.hasRenamedSegments) {\n this.cutOverToMemory(\"renamed-property\");\n }\n }\n\n if (name === \"join\") {\n const joinValue = value as QueryOptionValueMap<T>[\"join\"];\n\n // A join whose two sides live on different plugins cannot be sent to EITHER of\n // them — neither can read the other's rows — so the option itself belongs to the\n // memory half, where the datastore interprets it.\n //\n // Set BEFORE the item is created, unlike `nearest`'s ratchet below, because this\n // moves the join option itself rather than everything after it.\n if (joinValue.crossPlugin === true) {\n this.cutOverToMemory(\"cross-plugin-join\");\n }\n }\n\n const item: QueryCollectionItem<T, K> = {\n index: this.nextIndex,\n option: {\n name,\n target: this.nextExecutionTarget,\n value,\n ...(this.nextExecutionReason == null ? {} : { reason: this.nextExecutionReason })\n }\n }\n\n this.nextIndex++;\n\n const found = this.options.get(name);\n\n this.options.set(name, [...found ?? [], item]);\n\n if (name === \"nearest\") {\n // Everything AFTER a similarity search runs in memory, whatever the backend.\n //\n // Whether the search was pushed down is a fact about the plugin, which this\n // collection cannot see — so a later option is only safe if it runs after the\n // scoring definitely happened, and in memory is the only place that is true of.\n //\n // The failure this prevents is silent. `.nearest(x => x.embedding, v, 10).take(3)`\n // sends `LIMIT 3` to a backend that ignored the ordering, so three arbitrary rows\n // come back and get scored — three real rows, in a plausible order, and not the\n // three nearest. Nothing errors.\n //\n // A plugin that DID push the search down loses nothing but the chance to also\n // push down what follows it, which is a limit over ten rows.\n this.cutOverToMemory(\"after-nearest\");\n }\n\n if (name === \"join\") {\n // Everything AFTER a join runs in memory, for the same reason as `nearest`: this\n // collection cannot see HOW the plugin executed the join, and the rows it produced\n // are TUPLES rather than entities of the root schema.\n //\n // A `take` sent to a backend that hash-joined in its translator would limit the\n // OUTER rows read, not the pairs produced — a plausible-looking result with the\n // wrong number of rows in it. Conjuncts that can safely run earlier are split off\n // by the query builder BEFORE dispatch, which is the only exception.\n this.cutOverToMemory(\"after-join\");\n }\n }\n\n /**\n * Splits the collection around the FIRST occurrence of `name`, preserving order.\n *\n * For a join: the options recorded before it operate on entity rows, the option itself\n * produces tuples, and the ones after it operate on tuples. Three different shapes, so the\n * caller has to run them in three steps rather than one pass.\n */\n splitAt<K extends QueryOptionName>(name: K): { before: QueryOptionsCollection<T>, at: QueryOption<T, K> | null, after: QueryOptionsCollection<T> } {\n this.resolveEnumeration();\n\n const sortedItems = this.enumeratedItems.toSorted((a, b) => a.index - b.index);\n const before = new QueryOptionsCollection<T>();\n const after = new QueryOptionsCollection<T>();\n\n before.derived = true;\n after.derived = true;\n let at: QueryOption<T, K> | null = null;\n\n for (let i = 0, length = sortedItems.length; i < length; i++) {\n const { option } = sortedItems[i];\n\n if (at == null && option.name === name) {\n at = option as QueryOption<T, K>;\n continue;\n }\n\n const destination = at == null ? before : after;\n destination.add(option.name, option.value);\n }\n\n return { before, at, after };\n }\n\n /**\n * Captures the collection's current state and returns a function that restores it.\n *\n * Terminal queryable operations (count, first, aggregates, …) record their option on\n * the shared collection before executing. Without restoring, a re-executed terminal —\n * the whole point of a subscribed queryable — stacks its option a second time and\n * runs it over the first execution's scalar result.\n */\n snapshot(): () => void {\n const options = new Map([...this.options.entries()].map(([key, items]): [QueryOptionName, QueryCollectionItem<any, any>[]] => [key, [...items]]));\n const nextExecutionTarget = this.nextExecutionTarget;\n const nextExecutionReason = this.nextExecutionReason;\n const nextIndex = this.nextIndex;\n\n return () => {\n this.options = new Map(options);\n this.nextExecutionTarget = nextExecutionTarget;\n this.nextExecutionReason = nextExecutionReason;\n this.nextIndex = nextIndex;\n this.enumeratedItems = [];\n };\n }\n\n split(): { memory: QueryOptionsCollection<T>, database: QueryOptionsCollection<T> } {\n this.resolveEnumeration();\n\n const sortedItems = this.enumeratedItems.toSorted((a, b) => a.index - b.index);\n const memoryQueryOptionsCollection = new QueryOptionsCollection<T>();\n const databaseQueryOptionsCollection = new QueryOptionsCollection<T>();\n\n memoryQueryOptionsCollection.derived = true;\n databaseQueryOptionsCollection.derived = true;\n\n for (let i = 0, length = sortedItems.length; i < length; i++) {\n const sortedItem = sortedItems[i];\n\n if (sortedItem.option.target === \"database\") {\n databaseQueryOptionsCollection.add(sortedItem.option.name, sortedItem.option.value);\n continue;\n }\n\n memoryQueryOptionsCollection.add(sortedItem.option.name, sortedItem.option.value);\n }\n\n return {\n memory: memoryQueryOptionsCollection,\n database: databaseQueryOptionsCollection\n }\n }\n\n hasTransformations(): boolean {\n const transformationOptions: QueryOptionName[] = [\"map\", \"group\", \"min\", \"max\", \"count\", \"sum\"];\n return transformationOptions.some((name) => this.options.has(name));\n }\n\n has<K extends QueryOptionName>(name: K): boolean {\n return this.options.has(name);\n }\n\n get<K extends QueryOptionName>(name: K): QueryCollectionItem<T, K>[] {\n return this.options.get(name) ?? [] as QueryCollectionItem<T, K>[];\n }\n\n getLast<K extends QueryOptionName>(name: K): QueryOption<T, K> | null {\n this.resolveEnumeration();\n\n for (let i = this.enumeratedItems.length - 1; i >= 0; i--) {\n const item = this.enumeratedItems[i];\n\n if (item.option.name === name) {\n return item.option;\n }\n }\n\n return null\n }\n\n getValues<K extends QueryOptionName>(name: K): QueryCollectionItem<T, K>[\"option\"][\"value\"][] | undefined {\n\n const found = this.options.get(name);\n\n if (found == null) {\n return [];\n }\n\n return found.map(w => w.option.value) as QueryCollectionItem<T, K>[\"option\"][\"value\"][];\n }\n\n private getEnumeration() {\n return [...this.options.values()].flat().toSorted((a, b) => a.index - b.index);\n }\n\n private resolveEnumeration() {\n if (this.enumeratedItems.length != this.nextIndex) {\n this.enumeratedItems = this.getEnumeration();\n }\n }\n\n forEach(iterator: (item: QueryCollectionItem<T, any>[\"option\"]) => void) {\n this.resolveEnumeration();\n\n for (let i = 0, length = this.enumeratedItems.length; i < length; i++) {\n iterator(this.enumeratedItems[i].option);\n }\n }\n}","export const isDate = (data: unknown): data is Date => {\n if (data == null) {\n return false;\n }\n\n if (typeof data !== \"object\") {\n return false;\n }\n\n return data instanceof Date;\n}","/**\n * Levelled logging, resolved once.\n *\n * Three things about the previous implementation drove this shape:\n *\n * - **There was no way to turn logging off.** `globalThis.__ROUTIER_DEBUG__` was only ever\n * compared against `true`, so setting it to `false` did nothing — while\n * `docs/how-to/debug-logging.md` documented exactly that as the way to force logging off.\n * A documented switch that silently does nothing is worse than no switch.\n * - **`NODE_ENV === 'test'` enabled it.** Every Jest run therefore logged, because Jest always\n * sets `NODE_ENV=test`. Measured on the S7 stress scenario, which drives ~2,000 saves through\n * a plugin that logs three lines per query: 12.4s with logging, ~6s without. Test runners also\n * capture console output by snapshotting a stack trace per call, so the cost is far above what\n * writing to a terminal would suggest — and the output buries whatever the failure was.\n * - **It was all-or-nothing, and re-resolved per call.** An error could not be kept while debug\n * was dropped, and every one of the ~97 call sites re-read `globalThis` and `process.env`.\n *\n * Levels are compared numerically against a value cached at module load. Measured against a\n * no-op console at 200k calls: an enabled call costs ~70ns, a call rejected by the gate ~3ns.\n * Building the arguments the call site passes in accounts for ~0.2ns of that 3ns, which is why\n * this keeps the ordinary `logger.debug(msg, payload)` signature instead of taking a thunk —\n * a lazy API would recover 0.3% of an enabled call's cost and would have to change every call\n * site to do it.\n */\n\n/** Ordered from most severe to most verbose. `silent` discards everything. */\nexport const LOG_LEVELS = ['silent', 'error', 'warn', 'info', 'debug'] as const;\n\nexport type LogLevel = (typeof LOG_LEVELS)[number];\n\n/** Numeric rank, so a gate is one integer comparison. */\nconst RANK: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n};\n\nconst isLogLevel = (value: unknown): value is LogLevel =>\n typeof value === 'string' && (LOG_LEVELS as readonly string[]).includes(value);\n\n/**\n * Resolves the configured level, in precedence order.\n *\n * Ordered most specific first: an explicit level beats a boolean flag, a boolean flag beats an\n * environment variable, and an environment variable beats an inference from `NODE_ENV`. Anything\n * unrecognised is ignored rather than treated as an error — a typo'd level should not take down\n * an application, and `silent` is the safe direction to fall back to.\n */\nconst resolveLevel = (): LogLevel => {\n if (typeof globalThis !== 'undefined') {\n const g = globalThis as { __ROUTIER_LOG_LEVEL__?: unknown; __ROUTIER_DEBUG__?: unknown };\n\n if (isLogLevel(g.__ROUTIER_LOG_LEVEL__)) {\n return g.__ROUTIER_LOG_LEVEL__;\n }\n\n // Both directions honoured. `=== false` used to fall through to the NODE_ENV checks\n // below and re-enable the logging it was asked to suppress.\n if (g.__ROUTIER_DEBUG__ === true) return 'debug';\n if (g.__ROUTIER_DEBUG__ === false) return 'silent';\n }\n\n // There is deliberately no `import.meta.env` branch, although the documentation used to\n // promise one. It could never work: this package is bundled with rspack, which replaces\n // `import.meta` with `undefined`, so the check would read the *library's* build-time\n // environment rather than the application's — and referencing `import.meta` at all is a parse\n // error under a CommonJS build target, which is how the test suite loads this file. Vite and\n // similar apps set `__ROUTIER_LOG_LEVEL__` or `__ROUTIER_DEBUG__` from their own\n // `import.meta.env`, which is what the docs now describe.\n if (typeof process !== 'undefined' && process.env != null) {\n if (isLogLevel(process.env.ROUTIER_LOG_LEVEL)) {\n return process.env.ROUTIER_LOG_LEVEL as LogLevel;\n }\n\n const debug = process.env.DEBUG;\n if (debug === 'routier' || debug === '*') return 'debug';\n\n const env = process.env.NODE_ENV?.toLowerCase();\n\n // `test` is deliberately absent. It used to be here, which meant no test suite anywhere\n // could run Routier quietly. Opt in with DEBUG=routier or ROUTIER_LOG_LEVEL when a test\n // needs the output.\n if (env === 'dev' || env === 'development') return 'debug';\n }\n\n return 'silent';\n};\n\nlet level: LogLevel = resolveLevel();\nlet rank = RANK[level];\n\n/**\n * Overrides the level for the rest of the process.\n *\n * The configuration above is read once, at import, which is what makes the gate cheap — but it\n * also means an application that decides its verbosity after startup, or a test that wants to\n * assert on output, has no way in. This is that way in.\n */\nexport const setLogLevel = (next: LogLevel): void => {\n if (isLogLevel(next) === false) {\n throw new Error(`Unknown log level \"${next}\". Expected one of: ${LOG_LEVELS.join(', ')}`);\n }\n\n level = next;\n rank = RANK[next];\n};\n\nexport const getLogLevel = (): LogLevel => level;\n\n/** Re-reads the environment. For tests that change it after this module was imported. */\nexport const resetLogLevel = (): void => {\n level = resolveLevel();\n rank = RANK[level];\n};\n\n/**\n * Whether a message at this level would be emitted.\n *\n * For the rare call site whose *arguments* are expensive to build — a serialization, a deep\n * clone, a join over a large collection. An ordinary payload object is not worth guarding; see\n * the measurement in the header.\n */\nexport const isLogLevelEnabled = (at: LogLevel): boolean => rank >= RANK[at];\n\ntype ConsoleMethod = 'log' | 'info' | 'warn' | 'error' | 'debug' | 'table';\n\nconst emit = (at: LogLevel, method: ConsoleMethod, args: unknown[]) => {\n if (rank < RANK[at]) {\n return;\n }\n\n // Resolved at call time rather than captured once: test harnesses and browser devtools both\n // replace console methods after modules have loaded, and a captured reference would keep\n // writing past the replacement.\n (console[method] as (...a: unknown[]) => void)(...args);\n};\n\nexport const logger = {\n /** General-purpose output. Carried at `info`, since `log` names a console method, not a level. */\n log: (...args: unknown[]): void => emit('info', 'log', args),\n info: (...args: unknown[]): void => emit('info', 'info', args),\n warn: (...args: unknown[]): void => emit('warn', 'warn', args),\n error: (...args: unknown[]): void => emit('error', 'error', args),\n debug: (...args: unknown[]): void => emit('debug', 'debug', args),\n /** Diagnostic tabular output; verbose by nature, so it sits at `debug`. */\n table: (...args: unknown[]): void => emit('debug', 'table', args),\n};\n","export const hash = (value: string, seed: number = 0) => {\n // From Stack Overflow\n // https://stackoverflow.com/a/52171480/3329760\n let h1 = 0xdeadbeef ^ seed, h2 = 0x41c6ce57 ^ seed;\n\n for (let i = 0, ch: number; i < value.length; i++) {\n ch = value.charCodeAt(i);\n h1 = Math.imul(h1 ^ ch, 2654435761);\n h2 = Math.imul(h2 ^ ch, 1597334677);\n }\n\n h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507);\n h1 ^= Math.imul(h2 ^ (h2 >>> 13), 3266489909);\n h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507);\n h2 ^= Math.imul(h1 ^ (h1 >>> 13), 3266489909);\n\n return 4294967296 * (2097151 & h2) + (h1 >>> 0);\n}\n\n/**\n * Fast string hash optimized for comparisons.\n * Uses djb2 algorithm - very fast and good distribution for short to medium strings.\n * Same input always produces same output (deterministic).\n * \n * @param value - The string to hash\n * @param seed - Optional seed value (default: 5381)\n * @returns A positive 32-bit integer hash value\n * \n * @example\n * ```ts\n * fastHash(\"test\") === fastHash(\"test\") // true\n * fastHash(\"test\") !== fastHash(\"test2\") // true\n * ```\n */\nexport const fastHash = (value: string, seed: number = 5381): number => {\n let hash = seed;\n for (let i = 0; i < value.length; i++) {\n hash = ((hash << 5) + hash) + value.charCodeAt(i);\n }\n return hash >>> 0; // Convert to unsigned 32-bit integer\n}\n\n/**\n * Converts any value to a readable string representation.\n * Handles primitives, objects, arrays, classes, dates, errors, and functions.\n * Supports depth limiting to prevent infinite recursion on circular references.\n * \n * @param obj - The value to stringify\n * @param maxDepth - Maximum depth for nested objects (default: 3)\n * @param currentDepth - Current recursion depth (default: 0)\n * @returns String representation of the value\n * \n * @example\n * ```ts\n * stringifyObject({ name: \"test\", count: 5 }) // '{ name: \"test\", count: 5 }'\n * stringifyObject([1, 2, 3]) // '[1, 2, 3]'\n * stringifyObject(new Date()) // 'Date(2024-01-01T00:00:00.000Z)'\n * ```\n */\nexport function stringifyObject(obj: unknown, maxDepth: number = 3, currentDepth: number = 0): string {\n if (obj === null) return 'null';\n if (obj === undefined) return 'undefined';\n\n const type = typeof obj;\n\n switch (type) {\n case 'string':\n return `\"${obj}\"`;\n case 'number':\n case 'boolean':\n return String(obj);\n case 'function':\n return `[Function: ${getFunctionName(obj as Function)}]`;\n case 'object':\n if (currentDepth >= maxDepth) {\n return '[Max Depth Reached]';\n }\n return stringifyObjectValue(obj, maxDepth, currentDepth);\n default:\n return `[${type}]`;\n }\n}\n\nfunction getFunctionName(fn: Function): string {\n const name = fn.name;\n return name || 'anonymous';\n}\n\nfunction getObjectProperties(obj: any): Record<string, any> {\n const properties: Record<string, any> = {};\n\n for (const key in obj) {\n if (obj.hasOwnProperty(key)) {\n properties[key] = obj[key];\n }\n }\n\n return properties;\n}\n\nfunction stringifyObjectValue(obj: any, maxDepth: number, currentDepth: number): string {\n if (obj === null) return 'null';\n\n if (obj instanceof Date) {\n return `Date(${obj.toISOString()})`;\n }\n\n if (obj instanceof Error) {\n return `Error(${obj.message})`;\n }\n\n if (obj instanceof RegExp) {\n return obj.toString();\n }\n\n if (Array.isArray(obj)) {\n return stringifyArray(obj, maxDepth, currentDepth);\n }\n\n if (obj.constructor && obj.constructor.name !== 'Object') {\n return stringifyClassInstance(obj, maxDepth, currentDepth);\n }\n\n return stringifyPlainObject(obj, maxDepth, currentDepth);\n}\n\nfunction stringifyArray(arr: any[], maxDepth: number, currentDepth: number): string {\n if (arr.length === 0) return '[]';\n\n const items = arr.slice(0, 5).map(item =>\n stringifyObject(item, maxDepth, currentDepth + 1)\n );\n\n const suffix = arr.length > 5 ? `... (+${arr.length - 5} more)` : '';\n return `[${items.join(', ')}${suffix}]`;\n}\n\nfunction stringifyClassInstance(obj: any, maxDepth: number, currentDepth: number): string {\n const className = obj.constructor.name;\n const properties = getObjectProperties(obj);\n\n if (Object.keys(properties).length === 0) {\n return `${className} {}`;\n }\n\n const props = Object.entries(properties)\n .slice(0, 5)\n .map(([key, value]) => {\n const isPrimitive = value === null || value === undefined ||\n (typeof value !== 'object' && typeof value !== 'function');\n const depth = isPrimitive ? currentDepth : currentDepth + 1;\n return `${key}: ${stringifyObject(value, maxDepth, depth)}`;\n });\n\n const suffix = Object.keys(properties).length > 5 ?\n `... (+${Object.keys(properties).length - 5} more)` : '';\n\n return `${className} { ${props.join(', ')}${suffix} }`;\n}\n\nfunction stringifyPlainObject(obj: any, maxDepth: number, currentDepth: number): string {\n const properties = getObjectProperties(obj);\n\n if (Object.keys(properties).length === 0) {\n return '{}';\n }\n\n const props = Object.entries(properties)\n .slice(0, 5)\n .map(([key, value]) => {\n const isPrimitive = value === null || value === undefined ||\n (typeof value !== 'object' && typeof value !== 'function');\n const depth = isPrimitive ? currentDepth : currentDepth + 1;\n return `${key}: ${stringifyObject(value, maxDepth, depth)}`;\n });\n\n const suffix = Object.keys(properties).length > 5 ?\n `... (+${Object.keys(properties).length - 5} more)` : '';\n\n return `{ ${props.join(', ')}${suffix} }`;\n}","export const uuid = (length: number = 16): string => {\n const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n const charLength = chars.length;\n let result = '';\n\n for (let i = 0; i < length; i++) {\n result += chars[Math.random() * charLength | 0];\n }\n return result;\n}\n\nconst HEX_CHARS = '0123456789abcdef';\nconst UUID_TEMPLATE = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';\n\nconst hasCrypto =\n typeof crypto !== 'undefined' && typeof crypto.getRandomValues === 'function';\n\nconst hasRandomUUID =\n typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function';\n\nexport const uuidv4 = (): string => {\n if (hasRandomUUID) {\n return crypto.randomUUID();\n }\n\n return uuidv4Fallback();\n};\n\nconst uuidv4Fallback = (): string => {\n let randomBytes: Uint8Array | null = null;\n if (hasCrypto) {\n randomBytes = crypto.getRandomValues(new Uint8Array(16));\n }\n\n let byteIndex = 0;\n let uuid = '';\n\n for (let i = 0; i < UUID_TEMPLATE.length; i++) {\n const c = UUID_TEMPLATE[i];\n if (c === '-') {\n uuid += '-';\n continue;\n }\n\n let r: number;\n if (hasCrypto && randomBytes) {\n // Each byte gives two hex digits (nibbles)\n r =\n (i % 2 === 0\n ? randomBytes[byteIndex] >> 4\n : randomBytes[byteIndex++] & 0x0f);\n } else {\n r = Math.floor(Math.random() * 16);\n }\n\n if (c === 'x') {\n uuid += HEX_CHARS[r];\n } else if (c === 'y') {\n // Variant bits: 8, 9, A, or B\n uuid += HEX_CHARS[(r & 0x3) | 0x8];\n } else if (c === '4') {\n uuid += '4';\n }\n }\n\n return uuid;\n};\n","__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n }\n }\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export const toMap = <T extends {}>(data: T[], keySelector: (item: T) => T[keyof T] | string) => {\n\n const result = new Map<T[keyof T] | string, T>();\n\n for (let i = 0; i < data.length; i++) {\n const item = data[i];\n const key = keySelector(item);\n result.set(key, item);\n }\n\n return result;\n}\n","export const cast = <TIn, TOut>(item: TIn) => {\n return item as unknown as TOut;\n}\n\nexport function clone<T extends {}>(data: T): T {\n return JSON.parse(JSON.stringify(data)) as T;\n}","export const isNodeRuntime = () => typeof process !== 'undefined' &&\n process.versions != null &&\n process.versions.node != null;","import { BulkPersistResult, BulkPersistChanges } from \"../collections\";\nimport { DbPluginBulkPersistEvent } from \"../plugins\";\n\nexport const resolveBulkPersistChanges = (event: DbPluginBulkPersistEvent, result: BulkPersistResult, bulkPersistChanges: BulkPersistChanges) => {\n // make sure we swap the adds here, that way we can make sure other persist events\n // don't take their additions and try to change subsequent calls\n for (const [schemaId, changes] of event.operation) {\n\n const schemmaBulkPersistResult = result.get(schemaId);\n const schemaBulkPersistChanges = bulkPersistChanges.resolve(schemaId);\n\n // Set the original removes\n schemaBulkPersistChanges.removes = changes.removes;\n\n // Set the original updates\n schemaBulkPersistChanges.updates = changes.updates;\n\n // Take the adds from the result and set them to be persisted\n // in the replicated plugins because the id's are set in the \n // memory data store\n schemaBulkPersistChanges.adds = schemmaBulkPersistResult.adds;\n }\n}","import { QueryOptionsCollection } from \"../plugins/query\";\n\nexport const combineQueryOptionsCollections = <T>(...collections: QueryOptionsCollection<T>[]) => {\n const result = new QueryOptionsCollection<T>();\n\n for (let i = 0, length = collections.length; i < length; i++) {\n const collection = collections[i];\n\n // Add scoped items first\n collection.forEach(item => {\n result.add(item.name, item.value);\n });\n }\n\n return result;\n}","import { InferCreateType, InferType, SchemaId } from \"../schema\";\nimport { DbPluginBulkPersistEvent, EntityUpdateInfo } from \"../plugins\";\n\ntype DbEvent = {\n type: \"add\",\n data: InferCreateType<unknown>;\n} | {\n type: \"update\",\n data: EntityUpdateInfo<unknown>;\n} | {\n type: \"remove\",\n data: InferType<unknown>;\n}\n\nexport const toEventArray = (event: DbPluginBulkPersistEvent): [SchemaId, DbEvent][] => {\n\n const result: [SchemaId, DbEvent][] = [];\n for (const [schemaId, changes] of event.operation) {\n\n if (changes.hasItems === false) {\n continue;\n }\n\n if (changes.adds.length > 0) {\n result.push(...changes.adds.map(add => {\n return [schemaId as SchemaId, { data: { ...add }, type: \"add\" }] as [SchemaId, DbEvent];\n }));\n }\n\n if (changes.updates.length > 0) {\n result.push(...changes.updates.map(update => {\n return [schemaId as SchemaId, { data: { ...update }, type: \"update\" }] as [SchemaId, DbEvent];\n }));\n }\n\n if (changes.removes.length > 0) {\n result.push(...changes.removes.map(remove => {\n return [schemaId as SchemaId, { data: { ...remove }, type: \"remove\" }] as [SchemaId, DbEvent];\n }));\n }\n }\n\n return result\n}","export const noop = (..._args: any[]) => { };","export const unsafeCast = <T>(value: unknown): T => {\n return value as T\n}","export * from './arrays';\nexport * from './strings';\nexport * from './dates';\nexport * from './objects';\nexport * from './runtime';\nexport * from './uuid';\nexport * from './replication';\nexport * from './types';\nexport * from './queryOptionsCollection';\nexport * from './dbPluginEventUtils';\nexport * from './functions';\nexport * from './unsafeCast';\nexport * from './logger';"],"names":["EXPRESSION_TYPES","isDate","assertDate","data","TypeError","assertIsNotNull","message","assertIsArray","Array","assertString","assertInstanceOf","value","Instance","assertIsNumber","isObjectWithType","isExpression","isOperatorExpression","isComparatorExpression","isPropertyExpression","isValueExpression","isEmptyExpression","isNotParsableExpression","getProperties","expression","properties","traverse","expr","forEach","callback","QueryOptionsCollection","Map","reason","options","name","mapValue","x","filterValue","sortValue","nearestValue","joinValue","item","found","sortedItems","a","b","before","after","at","i","length","option","destination","key","items","nextExecutionTarget","nextExecutionReason","nextIndex","memoryQueryOptionsCollection","databaseQueryOptionsCollection","sortedItem","transformationOptions","w","iterator","Date","LOG_LEVELS","RANK","isLogLevel","resolveLevel","globalThis","g","process","debug","env","level","rank","setLogLevel","next","Error","getLogLevel","resetLogLevel","isLogLevelEnabled","emit","method","args","console","logger","hash","seed","h1","h2","ch","Math","fastHash","stringifyObject","obj","maxDepth","currentDepth","undefined","type","String","getFunctionName","stringifyObjectValue","fn","getObjectProperties","RegExp","stringifyArray","stringifyClassInstance","stringifyPlainObject","arr","suffix","className","Object","props","isPrimitive","depth","uuid","chars","charLength","result","HEX_CHARS","UUID_TEMPLATE","hasCrypto","crypto","hasRandomUUID","uuidv4","uuidv4Fallback","randomBytes","Uint8Array","byteIndex","c","r","toMap","keySelector","cast","clone","JSON","isNodeRuntime","resolveBulkPersistChanges","event","bulkPersistChanges","schemaId","changes","schemmaBulkPersistResult","schemaBulkPersistChanges","combineQueryOptionsCollections","collections","collection","toEventArray","add","update","remove","noop","_args","unsafeCast"],"mappings":";;;;;;;AAA4D;AAEtB;AAE/B,SAASE,WAAWC,IAAa;IACpC,IAAIF,OAAOE,UAAU,OAAO;QACxB,MAAM,IAAIC,UAAU;IACxB;AACJ;AAEO,SAASC,gBAAmBF,IAA0B,EAAEG,OAAiC;IAC5F,IAAIH,QAAQ,MAAM;QACd,IAAIG,WAAW,MAAM;YACjB,MAAM,IAAIF,UAAU;QACxB;QAEA,IAAI,OAAOE,Y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QAE/C,IAAIG,QAAQ,QAAQ,KAAK,OAAO;YAC5B;QACJ;QAEA,IAAIA,QAAQ,IAAI,CAAC,MAAM,GAAG,GAAG;YACzBvB,OAAO,IAAI,IAAIuB,QAAQ,IAAI,CAAC,GAAG,CAACO,CAAAA;gBAC5B,OAAO;oBAACR;oBAAsB;wBAAE,MAAM;4BAAE,GAAGQ,GAAG;wBAAC;wBAAG,MAAM;oBAAM;iBAAE;YACpE;QACJ;QAEA,IAAIP,QAAQ,OAAO,CAAC,MAAM,GAAG,GAAG;YAC5BvB,OAAO,IAAI,IAAIuB,QAAQ,OAAO,CAAC,GAAG,CAACQ,CAAAA;gBAC/B,OAAO;oBAACT;oBAAsB;wBAAE,MAAM;4BAAE,GAAGS,MAAM;wBAAC;wBAAG,MAAM;oBAAS;iBAAE;YAC1E;QACJ;QAEA,IAAIR,QAAQ,OAAO,CAAC,MAAM,GAAG,GAAG;YAC5BvB,OAAO,IAAI,IAAIuB,QAAQ,OAAO,CAAC,GAAG,CAACS,CAAAA;gBAC/B,OAAO;oBAACV;oBAAsB;wBAAE,MAAM;4BAAE,GAAGU,MAAM;wBAAC;wBAAG,MAAM;oBAAS;iBAAE;YAC1E;QACJ;IACJ;IAEA,OAAOhC;AACX,EAAC;;;AC3CM,MAAMiC,OAAO,CAAC,GAAGC,SAAmB,EAAE;;;ACAtC,MAAMC,aAAa,CAAI9I;IAC1B,OAAOA;AACX,EAAC;;;;;ACFwB;AACC;AACF;AACE;AACA;AACH;AACO;AACN;AACiB;AACJ;AACT;AACC;AACJ"}
|
package/dist/utilities/index.js
CHANGED
|
@@ -148,8 +148,26 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
148
148
|
class QueryOptionsCollection {
|
|
149
149
|
options = new Map();
|
|
150
150
|
nextExecutionTarget = "database";
|
|
151
|
+
nextExecutionReason = null;
|
|
151
152
|
nextIndex = 0;
|
|
152
153
|
enumeratedItems = [];
|
|
154
|
+
/** Cuts over to memory execution, keeping the first cause. See `MemoryExecutionReason`. */ cutOverToMemory(reason) {
|
|
155
|
+
this.nextExecutionTarget = "memory";
|
|
156
|
+
if (this.nextExecutionReason == null) {
|
|
157
|
+
this.nextExecutionReason = reason;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* True when `split()` or `splitAt()` produced this collection.
|
|
162
|
+
*
|
|
163
|
+
* Those rebuild each half by re-adding its options, which re-derives execution targets
|
|
164
|
+
* without the options that caused them — a post-join filter alone in the memory half
|
|
165
|
+
* derives back to `"database"`. Anything reading `target` as a report of where work runs
|
|
166
|
+
* has to reject a derived collection; see `explainQuery`.
|
|
167
|
+
*/ derived = false;
|
|
168
|
+
get isDerived() {
|
|
169
|
+
return this.derived;
|
|
170
|
+
}
|
|
153
171
|
get items() {
|
|
154
172
|
return this.options;
|
|
155
173
|
}
|
|
@@ -170,7 +188,7 @@ class QueryOptionsCollection {
|
|
|
170
188
|
if (mapValue.fields.some((x)=>x.isRename === true) || mapValue.fields.some((x)=>x.property?.isUnmapped === true)) {
|
|
171
189
|
// Cut over to memory execution since we are renaming a property with .map
|
|
172
190
|
// We do not want to figure out how the new name flows through the entire query
|
|
173
|
-
this.
|
|
191
|
+
this.cutOverToMemory("map-rename");
|
|
174
192
|
}
|
|
175
193
|
}
|
|
176
194
|
if (name === "filter") {
|
|
@@ -182,13 +200,13 @@ class QueryOptionsCollection {
|
|
|
182
200
|
return;
|
|
183
201
|
}
|
|
184
202
|
if (filterValue.expression.type === "not-parsable") {
|
|
185
|
-
this.
|
|
203
|
+
this.cutOverToMemory("not-parsable");
|
|
186
204
|
} else {
|
|
187
205
|
(0,_expressions_utils__rspack_import_0/* .forEach */.j)(filterValue.expression, (expression)=>{
|
|
188
206
|
if ((0,_assertions__rspack_import_1/* .isPropertyExpression */.e3)(expression) && expression.property.isUnmapped) {
|
|
189
207
|
// Cut over to memory execution, unmapped properties are not in the database and
|
|
190
208
|
// cannot be queried
|
|
191
|
-
this.
|
|
209
|
+
this.cutOverToMemory("unmapped-property");
|
|
192
210
|
return false;
|
|
193
211
|
}
|
|
194
212
|
if ((0,_assertions__rspack_import_1/* .isPropertyExpression */.e3)(expression) && expression.property.hasRenamedSegments) {
|
|
@@ -196,7 +214,7 @@ class QueryOptionsCollection {
|
|
|
196
214
|
// `from` (storage) names, but filter selectors reference the
|
|
197
215
|
// in-memory names. Memory execution runs after deserialization,
|
|
198
216
|
// where the in-memory names exist
|
|
199
|
-
this.
|
|
217
|
+
this.cutOverToMemory("renamed-property");
|
|
200
218
|
return false;
|
|
201
219
|
}
|
|
202
220
|
return true;
|
|
@@ -207,8 +225,10 @@ class QueryOptionsCollection {
|
|
|
207
225
|
const sortValue = value;
|
|
208
226
|
// Same rule as filters: sort selectors reference in-memory names, which
|
|
209
227
|
// only exist after deserialization when the property is renamed or unmapped
|
|
210
|
-
if (sortValue.property != null &&
|
|
211
|
-
this.
|
|
228
|
+
if (sortValue.property != null && sortValue.property.isUnmapped) {
|
|
229
|
+
this.cutOverToMemory("unmapped-property");
|
|
230
|
+
} else if (sortValue.property != null && sortValue.property.hasRenamedSegments) {
|
|
231
|
+
this.cutOverToMemory("renamed-property");
|
|
212
232
|
}
|
|
213
233
|
}
|
|
214
234
|
if (name === "nearest") {
|
|
@@ -219,8 +239,10 @@ class QueryOptionsCollection {
|
|
|
219
239
|
//
|
|
220
240
|
// This is also what lets every translator's in-memory fallback read the column by
|
|
221
241
|
// its resolved name — anything whose storage name differs never reaches them.
|
|
222
|
-
if (nearestValue.property != null &&
|
|
223
|
-
this.
|
|
242
|
+
if (nearestValue.property != null && nearestValue.property.isUnmapped) {
|
|
243
|
+
this.cutOverToMemory("unmapped-property");
|
|
244
|
+
} else if (nearestValue.property != null && nearestValue.property.hasRenamedSegments) {
|
|
245
|
+
this.cutOverToMemory("renamed-property");
|
|
224
246
|
}
|
|
225
247
|
}
|
|
226
248
|
if (name === "join") {
|
|
@@ -232,7 +254,7 @@ class QueryOptionsCollection {
|
|
|
232
254
|
// Set BEFORE the item is created, unlike `nearest`'s ratchet below, because this
|
|
233
255
|
// moves the join option itself rather than everything after it.
|
|
234
256
|
if (joinValue.crossPlugin === true) {
|
|
235
|
-
this.
|
|
257
|
+
this.cutOverToMemory("cross-plugin-join");
|
|
236
258
|
}
|
|
237
259
|
}
|
|
238
260
|
const item = {
|
|
@@ -240,7 +262,10 @@ class QueryOptionsCollection {
|
|
|
240
262
|
option: {
|
|
241
263
|
name,
|
|
242
264
|
target: this.nextExecutionTarget,
|
|
243
|
-
value
|
|
265
|
+
value,
|
|
266
|
+
...this.nextExecutionReason == null ? {} : {
|
|
267
|
+
reason: this.nextExecutionReason
|
|
268
|
+
}
|
|
244
269
|
}
|
|
245
270
|
};
|
|
246
271
|
this.nextIndex++;
|
|
@@ -263,7 +288,7 @@ class QueryOptionsCollection {
|
|
|
263
288
|
//
|
|
264
289
|
// A plugin that DID push the search down loses nothing but the chance to also
|
|
265
290
|
// push down what follows it, which is a limit over ten rows.
|
|
266
|
-
this.
|
|
291
|
+
this.cutOverToMemory("after-nearest");
|
|
267
292
|
}
|
|
268
293
|
if (name === "join") {
|
|
269
294
|
// Everything AFTER a join runs in memory, for the same reason as `nearest`: this
|
|
@@ -274,7 +299,7 @@ class QueryOptionsCollection {
|
|
|
274
299
|
// OUTER rows read, not the pairs produced — a plausible-looking result with the
|
|
275
300
|
// wrong number of rows in it. Conjuncts that can safely run earlier are split off
|
|
276
301
|
// by the query builder BEFORE dispatch, which is the only exception.
|
|
277
|
-
this.
|
|
302
|
+
this.cutOverToMemory("after-join");
|
|
278
303
|
}
|
|
279
304
|
}
|
|
280
305
|
/**
|
|
@@ -288,6 +313,8 @@ class QueryOptionsCollection {
|
|
|
288
313
|
const sortedItems = this.enumeratedItems.toSorted((a, b)=>a.index - b.index);
|
|
289
314
|
const before = new QueryOptionsCollection();
|
|
290
315
|
const after = new QueryOptionsCollection();
|
|
316
|
+
before.derived = true;
|
|
317
|
+
after.derived = true;
|
|
291
318
|
let at = null;
|
|
292
319
|
for(let i = 0, length = sortedItems.length; i < length; i++){
|
|
293
320
|
const { option } = sortedItems[i];
|
|
@@ -321,10 +348,12 @@ class QueryOptionsCollection {
|
|
|
321
348
|
]
|
|
322
349
|
]));
|
|
323
350
|
const nextExecutionTarget = this.nextExecutionTarget;
|
|
351
|
+
const nextExecutionReason = this.nextExecutionReason;
|
|
324
352
|
const nextIndex = this.nextIndex;
|
|
325
353
|
return ()=>{
|
|
326
354
|
this.options = new Map(options);
|
|
327
355
|
this.nextExecutionTarget = nextExecutionTarget;
|
|
356
|
+
this.nextExecutionReason = nextExecutionReason;
|
|
328
357
|
this.nextIndex = nextIndex;
|
|
329
358
|
this.enumeratedItems = [];
|
|
330
359
|
};
|
|
@@ -334,6 +363,8 @@ class QueryOptionsCollection {
|
|
|
334
363
|
const sortedItems = this.enumeratedItems.toSorted((a, b)=>a.index - b.index);
|
|
335
364
|
const memoryQueryOptionsCollection = new QueryOptionsCollection();
|
|
336
365
|
const databaseQueryOptionsCollection = new QueryOptionsCollection();
|
|
366
|
+
memoryQueryOptionsCollection.derived = true;
|
|
367
|
+
databaseQueryOptionsCollection.derived = true;
|
|
337
368
|
for(let i = 0, length = sortedItems.length; i < length; i++){
|
|
338
369
|
const sortedItem = sortedItems[i];
|
|
339
370
|
if (sortedItem.option.target === "database") {
|