mongo.do 0.1.0 → 0.1.1
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/cli/index.d.ts +1 -15
- package/dist/cli/index.js +4083 -196
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +2740 -20
- package/dist/index.js +9375 -27
- package/dist/index.js.map +1 -1
- package/dist/worker-entrypoint-BEW23Gmp.d.ts +1331 -0
- package/dist/worker.d.ts +6 -5
- package/dist/worker.js +5477 -18
- package/dist/worker.js.map +1 -1
- package/package.json +3 -2
- package/dist/agentfs/adapters/anthropic.d.ts +0 -176
- package/dist/agentfs/adapters/anthropic.d.ts.map +0 -1
- package/dist/agentfs/adapters/anthropic.js +0 -629
- package/dist/agentfs/adapters/anthropic.js.map +0 -1
- package/dist/agentfs/adapters/index.d.ts +0 -21
- package/dist/agentfs/adapters/index.d.ts.map +0 -1
- package/dist/agentfs/adapters/index.js +0 -23
- package/dist/agentfs/adapters/index.js.map +0 -1
- package/dist/agentfs/adapters/vercel.d.ts +0 -260
- package/dist/agentfs/adapters/vercel.d.ts.map +0 -1
- package/dist/agentfs/adapters/vercel.js +0 -288
- package/dist/agentfs/adapters/vercel.js.map +0 -1
- package/dist/agentfs/glob.d.ts +0 -116
- package/dist/agentfs/glob.d.ts.map +0 -1
- package/dist/agentfs/glob.js +0 -270
- package/dist/agentfs/glob.js.map +0 -1
- package/dist/agentfs/grep.d.ts +0 -83
- package/dist/agentfs/grep.d.ts.map +0 -1
- package/dist/agentfs/grep.js +0 -193
- package/dist/agentfs/grep.js.map +0 -1
- package/dist/agentfs/index.d.ts +0 -22
- package/dist/agentfs/index.d.ts.map +0 -1
- package/dist/agentfs/index.js +0 -18
- package/dist/agentfs/index.js.map +0 -1
- package/dist/agentfs/kv-store.d.ts +0 -128
- package/dist/agentfs/kv-store.d.ts.map +0 -1
- package/dist/agentfs/kv-store.js +0 -227
- package/dist/agentfs/kv-store.js.map +0 -1
- package/dist/agentfs/mondo-agent.d.ts +0 -255
- package/dist/agentfs/mondo-agent.d.ts.map +0 -1
- package/dist/agentfs/mondo-agent.js +0 -879
- package/dist/agentfs/mondo-agent.js.map +0 -1
- package/dist/agentfs/toolcalls.d.ts +0 -130
- package/dist/agentfs/toolcalls.d.ts.map +0 -1
- package/dist/agentfs/toolcalls.js +0 -178
- package/dist/agentfs/toolcalls.js.map +0 -1
- package/dist/agentfs/types.d.ts +0 -171
- package/dist/agentfs/types.d.ts.map +0 -1
- package/dist/agentfs/types.js +0 -7
- package/dist/agentfs/types.js.map +0 -1
- package/dist/agentfs/vfs.d.ts +0 -249
- package/dist/agentfs/vfs.d.ts.map +0 -1
- package/dist/agentfs/vfs.js +0 -469
- package/dist/agentfs/vfs.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/mcp.d.ts +0 -119
- package/dist/cli/mcp.d.ts.map +0 -1
- package/dist/cli/mcp.js +0 -418
- package/dist/cli/mcp.js.map +0 -1
- package/dist/cli/server.d.ts +0 -179
- package/dist/cli/server.d.ts.map +0 -1
- package/dist/cli/server.js +0 -441
- package/dist/cli/server.js.map +0 -1
- package/dist/client/Collection.d.ts +0 -199
- package/dist/client/Collection.d.ts.map +0 -1
- package/dist/client/Collection.js +0 -256
- package/dist/client/Collection.js.map +0 -1
- package/dist/client/Database.d.ts +0 -68
- package/dist/client/Database.d.ts.map +0 -1
- package/dist/client/Database.js +0 -105
- package/dist/client/Database.js.map +0 -1
- package/dist/client/MongoClient.d.ts +0 -165
- package/dist/client/MongoClient.d.ts.map +0 -1
- package/dist/client/MongoClient.js +0 -307
- package/dist/client/MongoClient.js.map +0 -1
- package/dist/client/aggregation-cursor.d.ts +0 -210
- package/dist/client/aggregation-cursor.d.ts.map +0 -1
- package/dist/client/aggregation-cursor.js +0 -509
- package/dist/client/aggregation-cursor.js.map +0 -1
- package/dist/client/bulk-write.d.ts +0 -216
- package/dist/client/bulk-write.d.ts.map +0 -1
- package/dist/client/bulk-write.js +0 -63
- package/dist/client/bulk-write.js.map +0 -1
- package/dist/client/change-stream.d.ts +0 -245
- package/dist/client/change-stream.d.ts.map +0 -1
- package/dist/client/change-stream.js +0 -429
- package/dist/client/change-stream.js.map +0 -1
- package/dist/client/cursor.d.ts +0 -85
- package/dist/client/cursor.d.ts.map +0 -1
- package/dist/client/cursor.js +0 -156
- package/dist/client/cursor.js.map +0 -1
- package/dist/client/http-cursor.d.ts +0 -233
- package/dist/client/http-cursor.d.ts.map +0 -1
- package/dist/client/http-cursor.js +0 -496
- package/dist/client/http-cursor.js.map +0 -1
- package/dist/client/index.d.ts +0 -18
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js +0 -24
- package/dist/client/index.js.map +0 -1
- package/dist/client/mongo-client.d.ts +0 -60
- package/dist/client/mongo-client.d.ts.map +0 -1
- package/dist/client/mongo-client.js +0 -190
- package/dist/client/mongo-client.js.map +0 -1
- package/dist/client/mongo-collection.d.ts +0 -359
- package/dist/client/mongo-collection.d.ts.map +0 -1
- package/dist/client/mongo-collection.js +0 -1641
- package/dist/client/mongo-collection.js.map +0 -1
- package/dist/client/mongo-cursor.d.ts +0 -257
- package/dist/client/mongo-cursor.d.ts.map +0 -1
- package/dist/client/mongo-cursor.js +0 -621
- package/dist/client/mongo-cursor.js.map +0 -1
- package/dist/client/mongo-database.d.ts +0 -88
- package/dist/client/mongo-database.d.ts.map +0 -1
- package/dist/client/mongo-database.js +0 -139
- package/dist/client/mongo-database.js.map +0 -1
- package/dist/client/session.d.ts +0 -210
- package/dist/client/session.d.ts.map +0 -1
- package/dist/client/session.js +0 -326
- package/dist/client/session.js.map +0 -1
- package/dist/durable-object/index-manager.d.ts +0 -173
- package/dist/durable-object/index-manager.d.ts.map +0 -1
- package/dist/durable-object/index-manager.js +0 -764
- package/dist/durable-object/index-manager.js.map +0 -1
- package/dist/durable-object/index.d.ts +0 -12
- package/dist/durable-object/index.d.ts.map +0 -1
- package/dist/durable-object/index.js +0 -8
- package/dist/durable-object/index.js.map +0 -1
- package/dist/durable-object/mcp-handler.d.ts +0 -52
- package/dist/durable-object/mcp-handler.d.ts.map +0 -1
- package/dist/durable-object/mcp-handler.js +0 -186
- package/dist/durable-object/mcp-handler.js.map +0 -1
- package/dist/durable-object/migrations.d.ts +0 -40
- package/dist/durable-object/migrations.d.ts.map +0 -1
- package/dist/durable-object/migrations.js +0 -121
- package/dist/durable-object/migrations.js.map +0 -1
- package/dist/durable-object/mondo-database.d.ts +0 -148
- package/dist/durable-object/mondo-database.d.ts.map +0 -1
- package/dist/durable-object/mondo-database.js +0 -621
- package/dist/durable-object/mondo-database.js.map +0 -1
- package/dist/durable-object/schema.d.ts +0 -192
- package/dist/durable-object/schema.d.ts.map +0 -1
- package/dist/durable-object/schema.js +0 -186
- package/dist/durable-object/schema.js.map +0 -1
- package/dist/embedding/document-serializer.d.ts +0 -118
- package/dist/embedding/document-serializer.d.ts.map +0 -1
- package/dist/embedding/document-serializer.js +0 -339
- package/dist/embedding/document-serializer.js.map +0 -1
- package/dist/embedding/embedding-manager.d.ts +0 -136
- package/dist/embedding/embedding-manager.d.ts.map +0 -1
- package/dist/embedding/embedding-manager.js +0 -176
- package/dist/embedding/embedding-manager.js.map +0 -1
- package/dist/embedding/index.d.ts +0 -9
- package/dist/embedding/index.d.ts.map +0 -1
- package/dist/embedding/index.js +0 -9
- package/dist/embedding/index.js.map +0 -1
- package/dist/executor/aggregation-executor.d.ts +0 -93
- package/dist/executor/aggregation-executor.d.ts.map +0 -1
- package/dist/executor/aggregation-executor.js +0 -275
- package/dist/executor/aggregation-executor.js.map +0 -1
- package/dist/executor/function-executor.d.ts +0 -39
- package/dist/executor/function-executor.d.ts.map +0 -1
- package/dist/executor/function-executor.js +0 -168
- package/dist/executor/function-executor.js.map +0 -1
- package/dist/executor/index.d.ts +0 -4
- package/dist/executor/index.d.ts.map +0 -1
- package/dist/executor/index.js +0 -4
- package/dist/executor/index.js.map +0 -1
- package/dist/executor/vector-search-executor.d.ts +0 -71
- package/dist/executor/vector-search-executor.d.ts.map +0 -1
- package/dist/executor/vector-search-executor.js +0 -113
- package/dist/executor/vector-search-executor.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/mcp/adapters/anthropic-adapter.d.ts +0 -256
- package/dist/mcp/adapters/anthropic-adapter.d.ts.map +0 -1
- package/dist/mcp/adapters/anthropic-adapter.js +0 -409
- package/dist/mcp/adapters/anthropic-adapter.js.map +0 -1
- package/dist/mcp/adapters/base-adapter.d.ts +0 -164
- package/dist/mcp/adapters/base-adapter.d.ts.map +0 -1
- package/dist/mcp/adapters/base-adapter.js +0 -277
- package/dist/mcp/adapters/base-adapter.js.map +0 -1
- package/dist/mcp/adapters/errors.d.ts +0 -173
- package/dist/mcp/adapters/errors.d.ts.map +0 -1
- package/dist/mcp/adapters/errors.js +0 -305
- package/dist/mcp/adapters/errors.js.map +0 -1
- package/dist/mcp/adapters/index.d.ts +0 -65
- package/dist/mcp/adapters/index.d.ts.map +0 -1
- package/dist/mcp/adapters/index.js +0 -92
- package/dist/mcp/adapters/index.js.map +0 -1
- package/dist/mcp/adapters/streaming.d.ts +0 -200
- package/dist/mcp/adapters/streaming.d.ts.map +0 -1
- package/dist/mcp/adapters/streaming.js +0 -381
- package/dist/mcp/adapters/streaming.js.map +0 -1
- package/dist/mcp/adapters/vercel-adapter.d.ts +0 -321
- package/dist/mcp/adapters/vercel-adapter.d.ts.map +0 -1
- package/dist/mcp/adapters/vercel-adapter.js +0 -487
- package/dist/mcp/adapters/vercel-adapter.js.map +0 -1
- package/dist/mcp/agent.d.ts +0 -192
- package/dist/mcp/agent.d.ts.map +0 -1
- package/dist/mcp/agent.js +0 -338
- package/dist/mcp/agent.js.map +0 -1
- package/dist/mcp/cli.d.ts +0 -71
- package/dist/mcp/cli.d.ts.map +0 -1
- package/dist/mcp/cli.js +0 -218
- package/dist/mcp/cli.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -15
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/index.js +0 -20
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/sandbox/database-proxy.d.ts +0 -118
- package/dist/mcp/sandbox/database-proxy.d.ts.map +0 -1
- package/dist/mcp/sandbox/database-proxy.js +0 -154
- package/dist/mcp/sandbox/database-proxy.js.map +0 -1
- package/dist/mcp/sandbox/index.d.ts +0 -8
- package/dist/mcp/sandbox/index.d.ts.map +0 -1
- package/dist/mcp/sandbox/index.js +0 -7
- package/dist/mcp/sandbox/index.js.map +0 -1
- package/dist/mcp/sandbox/miniflare-evaluator.d.ts +0 -72
- package/dist/mcp/sandbox/miniflare-evaluator.d.ts.map +0 -1
- package/dist/mcp/sandbox/miniflare-evaluator.js +0 -379
- package/dist/mcp/sandbox/miniflare-evaluator.js.map +0 -1
- package/dist/mcp/sandbox/template.d.ts +0 -48
- package/dist/mcp/sandbox/template.d.ts.map +0 -1
- package/dist/mcp/sandbox/template.js +0 -147
- package/dist/mcp/sandbox/template.js.map +0 -1
- package/dist/mcp/sandbox/worker-evaluator.d.ts +0 -160
- package/dist/mcp/sandbox/worker-evaluator.d.ts.map +0 -1
- package/dist/mcp/sandbox/worker-evaluator.js +0 -217
- package/dist/mcp/sandbox/worker-evaluator.js.map +0 -1
- package/dist/mcp/server.d.ts +0 -75
- package/dist/mcp/server.d.ts.map +0 -1
- package/dist/mcp/server.js +0 -278
- package/dist/mcp/server.js.map +0 -1
- package/dist/mcp/tool-call-auditor.d.ts +0 -188
- package/dist/mcp/tool-call-auditor.d.ts.map +0 -1
- package/dist/mcp/tool-call-auditor.js +0 -198
- package/dist/mcp/tool-call-auditor.js.map +0 -1
- package/dist/mcp/tools/do.d.ts +0 -51
- package/dist/mcp/tools/do.d.ts.map +0 -1
- package/dist/mcp/tools/do.js +0 -113
- package/dist/mcp/tools/do.js.map +0 -1
- package/dist/mcp/tools/fetch.d.ts +0 -43
- package/dist/mcp/tools/fetch.d.ts.map +0 -1
- package/dist/mcp/tools/fetch.js +0 -127
- package/dist/mcp/tools/fetch.js.map +0 -1
- package/dist/mcp/tools/index.d.ts +0 -9
- package/dist/mcp/tools/index.d.ts.map +0 -1
- package/dist/mcp/tools/index.js +0 -9
- package/dist/mcp/tools/index.js.map +0 -1
- package/dist/mcp/tools/search.d.ts +0 -60
- package/dist/mcp/tools/search.d.ts.map +0 -1
- package/dist/mcp/tools/search.js +0 -278
- package/dist/mcp/tools/search.js.map +0 -1
- package/dist/mcp/transport/http.d.ts +0 -144
- package/dist/mcp/transport/http.d.ts.map +0 -1
- package/dist/mcp/transport/http.js +0 -545
- package/dist/mcp/transport/http.js.map +0 -1
- package/dist/mcp/transport/index.d.ts +0 -10
- package/dist/mcp/transport/index.d.ts.map +0 -1
- package/dist/mcp/transport/index.js +0 -12
- package/dist/mcp/transport/index.js.map +0 -1
- package/dist/mcp/transport/stdio.d.ts +0 -132
- package/dist/mcp/transport/stdio.d.ts.map +0 -1
- package/dist/mcp/transport/stdio.js +0 -466
- package/dist/mcp/transport/stdio.js.map +0 -1
- package/dist/mcp/types.d.ts +0 -476
- package/dist/mcp/types.d.ts.map +0 -1
- package/dist/mcp/types.js +0 -178
- package/dist/mcp/types.js.map +0 -1
- package/dist/olap/cdc/cdc-buffer.d.ts +0 -92
- package/dist/olap/cdc/cdc-buffer.d.ts.map +0 -1
- package/dist/olap/cdc/cdc-buffer.js +0 -146
- package/dist/olap/cdc/cdc-buffer.js.map +0 -1
- package/dist/olap/cdc/cdc-emitter.d.ts +0 -118
- package/dist/olap/cdc/cdc-emitter.d.ts.map +0 -1
- package/dist/olap/cdc/cdc-emitter.js +0 -217
- package/dist/olap/cdc/cdc-emitter.js.map +0 -1
- package/dist/olap/cdc/cdc-schema.d.ts +0 -119
- package/dist/olap/cdc/cdc-schema.d.ts.map +0 -1
- package/dist/olap/cdc/cdc-schema.js +0 -253
- package/dist/olap/cdc/cdc-schema.js.map +0 -1
- package/dist/olap/cdc/index.d.ts +0 -10
- package/dist/olap/cdc/index.d.ts.map +0 -1
- package/dist/olap/cdc/index.js +0 -10
- package/dist/olap/cdc/index.js.map +0 -1
- package/dist/olap/clickhouse/iceberg.d.ts +0 -164
- package/dist/olap/clickhouse/iceberg.d.ts.map +0 -1
- package/dist/olap/clickhouse/iceberg.js +0 -138
- package/dist/olap/clickhouse/iceberg.js.map +0 -1
- package/dist/olap/clickhouse/index.d.ts +0 -14
- package/dist/olap/clickhouse/index.d.ts.map +0 -1
- package/dist/olap/clickhouse/index.js +0 -14
- package/dist/olap/clickhouse/index.js.map +0 -1
- package/dist/olap/clickhouse/mapper.d.ts +0 -170
- package/dist/olap/clickhouse/mapper.d.ts.map +0 -1
- package/dist/olap/clickhouse/mapper.js +0 -654
- package/dist/olap/clickhouse/mapper.js.map +0 -1
- package/dist/olap/clickhouse/olap-backend.d.ts +0 -181
- package/dist/olap/clickhouse/olap-backend.d.ts.map +0 -1
- package/dist/olap/clickhouse/olap-backend.js +0 -1083
- package/dist/olap/clickhouse/olap-backend.js.map +0 -1
- package/dist/olap/clickhouse/query-executor.d.ts +0 -163
- package/dist/olap/clickhouse/query-executor.d.ts.map +0 -1
- package/dist/olap/clickhouse/query-executor.js +0 -560
- package/dist/olap/clickhouse/query-executor.js.map +0 -1
- package/dist/olap/clickhouse/query.d.ts +0 -134
- package/dist/olap/clickhouse/query.d.ts.map +0 -1
- package/dist/olap/clickhouse/query.js +0 -512
- package/dist/olap/clickhouse/query.js.map +0 -1
- package/dist/olap/stage/index.d.ts +0 -6
- package/dist/olap/stage/index.d.ts.map +0 -1
- package/dist/olap/stage/index.js +0 -6
- package/dist/olap/stage/index.js.map +0 -1
- package/dist/olap/stage/parser.d.ts +0 -68
- package/dist/olap/stage/parser.d.ts.map +0 -1
- package/dist/olap/stage/parser.js +0 -293
- package/dist/olap/stage/parser.js.map +0 -1
- package/dist/olap/stage/router.d.ts +0 -94
- package/dist/olap/stage/router.d.ts.map +0 -1
- package/dist/olap/stage/router.js +0 -390
- package/dist/olap/stage/router.js.map +0 -1
- package/dist/rpc/endpoint.d.ts +0 -52
- package/dist/rpc/endpoint.d.ts.map +0 -1
- package/dist/rpc/endpoint.js +0 -734
- package/dist/rpc/endpoint.js.map +0 -1
- package/dist/rpc/index.d.ts +0 -34
- package/dist/rpc/index.d.ts.map +0 -1
- package/dist/rpc/index.js +0 -45
- package/dist/rpc/index.js.map +0 -1
- package/dist/rpc/rpc-client.d.ts +0 -275
- package/dist/rpc/rpc-client.d.ts.map +0 -1
- package/dist/rpc/rpc-client.js +0 -735
- package/dist/rpc/rpc-client.js.map +0 -1
- package/dist/rpc/rpc-target.d.ts +0 -220
- package/dist/rpc/rpc-target.d.ts.map +0 -1
- package/dist/rpc/rpc-target.js +0 -500
- package/dist/rpc/rpc-target.js.map +0 -1
- package/dist/rpc/worker-entrypoint.d.ts +0 -159
- package/dist/rpc/worker-entrypoint.d.ts.map +0 -1
- package/dist/rpc/worker-entrypoint.js +0 -212
- package/dist/rpc/worker-entrypoint.js.map +0 -1
- package/dist/server.d.ts +0 -18
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -129
- package/dist/server.js.map +0 -1
- package/dist/studio/components/browser/CollectionItem.d.ts +0 -26
- package/dist/studio/components/browser/CollectionItem.d.ts.map +0 -1
- package/dist/studio/components/browser/CollectionItem.js +0 -143
- package/dist/studio/components/browser/CollectionItem.js.map +0 -1
- package/dist/studio/components/browser/CollectionTree.d.ts +0 -45
- package/dist/studio/components/browser/CollectionTree.d.ts.map +0 -1
- package/dist/studio/components/browser/CollectionTree.js +0 -207
- package/dist/studio/components/browser/CollectionTree.js.map +0 -1
- package/dist/studio/components/browser/ConnectedDatabaseBrowser.d.ts +0 -51
- package/dist/studio/components/browser/ConnectedDatabaseBrowser.d.ts.map +0 -1
- package/dist/studio/components/browser/ConnectedDatabaseBrowser.js +0 -185
- package/dist/studio/components/browser/ConnectedDatabaseBrowser.js.map +0 -1
- package/dist/studio/components/browser/DatabaseBrowser.d.ts +0 -46
- package/dist/studio/components/browser/DatabaseBrowser.d.ts.map +0 -1
- package/dist/studio/components/browser/DatabaseBrowser.js +0 -304
- package/dist/studio/components/browser/DatabaseBrowser.js.map +0 -1
- package/dist/studio/components/browser/__tests__/CollectionItem.test.d.ts +0 -5
- package/dist/studio/components/browser/__tests__/CollectionItem.test.d.ts.map +0 -1
- package/dist/studio/components/browser/__tests__/CollectionItem.test.js +0 -169
- package/dist/studio/components/browser/__tests__/CollectionItem.test.js.map +0 -1
- package/dist/studio/components/browser/__tests__/CollectionTree.test.d.ts +0 -5
- package/dist/studio/components/browser/__tests__/CollectionTree.test.d.ts.map +0 -1
- package/dist/studio/components/browser/__tests__/CollectionTree.test.js +0 -203
- package/dist/studio/components/browser/__tests__/CollectionTree.test.js.map +0 -1
- package/dist/studio/components/browser/__tests__/DatabaseBrowser.e2e.test.d.ts +0 -8
- package/dist/studio/components/browser/__tests__/DatabaseBrowser.e2e.test.d.ts.map +0 -1
- package/dist/studio/components/browser/__tests__/DatabaseBrowser.e2e.test.js +0 -522
- package/dist/studio/components/browser/__tests__/DatabaseBrowser.e2e.test.js.map +0 -1
- package/dist/studio/components/browser/__tests__/DatabaseBrowser.test.d.ts +0 -5
- package/dist/studio/components/browser/__tests__/DatabaseBrowser.test.d.ts.map +0 -1
- package/dist/studio/components/browser/__tests__/DatabaseBrowser.test.js +0 -518
- package/dist/studio/components/browser/__tests__/DatabaseBrowser.test.js.map +0 -1
- package/dist/studio/components/browser/__tests__/setup.d.ts +0 -5
- package/dist/studio/components/browser/__tests__/setup.d.ts.map +0 -1
- package/dist/studio/components/browser/__tests__/setup.js +0 -22
- package/dist/studio/components/browser/__tests__/setup.js.map +0 -1
- package/dist/studio/components/browser/index.d.ts +0 -15
- package/dist/studio/components/browser/index.d.ts.map +0 -1
- package/dist/studio/components/browser/index.js +0 -10
- package/dist/studio/components/browser/index.js.map +0 -1
- package/dist/studio/components/browser/types.d.ts +0 -33
- package/dist/studio/components/browser/types.d.ts.map +0 -1
- package/dist/studio/components/browser/types.js +0 -5
- package/dist/studio/components/browser/types.js.map +0 -1
- package/dist/studio/components/connection/ConnectionForm.d.ts +0 -59
- package/dist/studio/components/connection/ConnectionForm.d.ts.map +0 -1
- package/dist/studio/components/connection/ConnectionForm.js +0 -274
- package/dist/studio/components/connection/ConnectionForm.js.map +0 -1
- package/dist/studio/components/connection/ConnectionList.d.ts +0 -59
- package/dist/studio/components/connection/ConnectionList.d.ts.map +0 -1
- package/dist/studio/components/connection/ConnectionList.js +0 -286
- package/dist/studio/components/connection/ConnectionList.js.map +0 -1
- package/dist/studio/components/connection/ConnectionPanel.d.ts +0 -132
- package/dist/studio/components/connection/ConnectionPanel.d.ts.map +0 -1
- package/dist/studio/components/connection/ConnectionPanel.js +0 -293
- package/dist/studio/components/connection/ConnectionPanel.js.map +0 -1
- package/dist/studio/components/connection/__tests__/ConnectionPanel.test.d.ts +0 -8
- package/dist/studio/components/connection/__tests__/ConnectionPanel.test.d.ts.map +0 -1
- package/dist/studio/components/connection/__tests__/ConnectionPanel.test.js +0 -632
- package/dist/studio/components/connection/__tests__/ConnectionPanel.test.js.map +0 -1
- package/dist/studio/components/connection/__tests__/setup.d.ts +0 -5
- package/dist/studio/components/connection/__tests__/setup.d.ts.map +0 -1
- package/dist/studio/components/connection/__tests__/setup.js +0 -11
- package/dist/studio/components/connection/__tests__/setup.js.map +0 -1
- package/dist/studio/components/connection/index.d.ts +0 -10
- package/dist/studio/components/connection/index.d.ts.map +0 -1
- package/dist/studio/components/connection/index.js +0 -7
- package/dist/studio/components/connection/index.js.map +0 -1
- package/dist/studio/components/crud/DeleteDocumentDialog.d.ts +0 -91
- package/dist/studio/components/crud/DeleteDocumentDialog.d.ts.map +0 -1
- package/dist/studio/components/crud/DeleteDocumentDialog.js +0 -273
- package/dist/studio/components/crud/DeleteDocumentDialog.js.map +0 -1
- package/dist/studio/components/crud/DocumentEditor.d.ts +0 -32
- package/dist/studio/components/crud/DocumentEditor.d.ts.map +0 -1
- package/dist/studio/components/crud/DocumentEditor.js +0 -546
- package/dist/studio/components/crud/DocumentEditor.js.map +0 -1
- package/dist/studio/components/crud/InsertDocumentDialog.d.ts +0 -78
- package/dist/studio/components/crud/InsertDocumentDialog.d.ts.map +0 -1
- package/dist/studio/components/crud/InsertDocumentDialog.js +0 -323
- package/dist/studio/components/crud/InsertDocumentDialog.js.map +0 -1
- package/dist/studio/components/crud/__tests__/DeleteDocumentDialog.test.d.ts +0 -5
- package/dist/studio/components/crud/__tests__/DeleteDocumentDialog.test.d.ts.map +0 -1
- package/dist/studio/components/crud/__tests__/DeleteDocumentDialog.test.js +0 -298
- package/dist/studio/components/crud/__tests__/DeleteDocumentDialog.test.js.map +0 -1
- package/dist/studio/components/crud/__tests__/DocumentEditor.test.d.ts +0 -8
- package/dist/studio/components/crud/__tests__/DocumentEditor.test.d.ts.map +0 -1
- package/dist/studio/components/crud/__tests__/DocumentEditor.test.js +0 -368
- package/dist/studio/components/crud/__tests__/DocumentEditor.test.js.map +0 -1
- package/dist/studio/components/crud/__tests__/InsertDocumentDialog.test.d.ts +0 -2
- package/dist/studio/components/crud/__tests__/InsertDocumentDialog.test.d.ts.map +0 -1
- package/dist/studio/components/crud/__tests__/InsertDocumentDialog.test.js +0 -352
- package/dist/studio/components/crud/__tests__/InsertDocumentDialog.test.js.map +0 -1
- package/dist/studio/components/crud/__tests__/setup.d.ts +0 -5
- package/dist/studio/components/crud/__tests__/setup.d.ts.map +0 -1
- package/dist/studio/components/crud/__tests__/setup.js +0 -22
- package/dist/studio/components/crud/__tests__/setup.js.map +0 -1
- package/dist/studio/components/crud/index.d.ts +0 -12
- package/dist/studio/components/crud/index.d.ts.map +0 -1
- package/dist/studio/components/crud/index.js +0 -11
- package/dist/studio/components/crud/index.js.map +0 -1
- package/dist/studio/hooks/useConnection.d.ts +0 -127
- package/dist/studio/hooks/useConnection.d.ts.map +0 -1
- package/dist/studio/hooks/useConnection.js +0 -414
- package/dist/studio/hooks/useConnection.js.map +0 -1
- package/dist/studio/hooks/useDatabaseBrowser.d.ts +0 -107
- package/dist/studio/hooks/useDatabaseBrowser.d.ts.map +0 -1
- package/dist/studio/hooks/useDatabaseBrowser.js +0 -294
- package/dist/studio/hooks/useDatabaseBrowser.js.map +0 -1
- package/dist/studio/index.d.ts +0 -16
- package/dist/studio/index.d.ts.map +0 -1
- package/dist/studio/index.js +0 -14
- package/dist/studio/index.js.map +0 -1
- package/dist/studio/types/connection.d.ts +0 -266
- package/dist/studio/types/connection.d.ts.map +0 -1
- package/dist/studio/types/connection.js +0 -159
- package/dist/studio/types/connection.js.map +0 -1
- package/dist/studio/vitest.config.d.ts +0 -3
- package/dist/studio/vitest.config.d.ts.map +0 -1
- package/dist/studio/vitest.config.js +0 -33
- package/dist/studio/vitest.config.js.map +0 -1
- package/dist/translator/aggregation-translator.d.ts +0 -51
- package/dist/translator/aggregation-translator.d.ts.map +0 -1
- package/dist/translator/aggregation-translator.js +0 -324
- package/dist/translator/aggregation-translator.js.map +0 -1
- package/dist/translator/dialect.d.ts +0 -131
- package/dist/translator/dialect.d.ts.map +0 -1
- package/dist/translator/dialect.js +0 -276
- package/dist/translator/dialect.js.map +0 -1
- package/dist/translator/geo-translator.d.ts +0 -91
- package/dist/translator/geo-translator.d.ts.map +0 -1
- package/dist/translator/geo-translator.js +0 -587
- package/dist/translator/geo-translator.js.map +0 -1
- package/dist/translator/hybrid-translator.d.ts +0 -70
- package/dist/translator/hybrid-translator.d.ts.map +0 -1
- package/dist/translator/hybrid-translator.js +0 -193
- package/dist/translator/hybrid-translator.js.map +0 -1
- package/dist/translator/index.d.ts +0 -13
- package/dist/translator/index.d.ts.map +0 -1
- package/dist/translator/index.js +0 -11
- package/dist/translator/index.js.map +0 -1
- package/dist/translator/query-translator.d.ts +0 -211
- package/dist/translator/query-translator.d.ts.map +0 -1
- package/dist/translator/query-translator.js +0 -1276
- package/dist/translator/query-translator.js.map +0 -1
- package/dist/translator/search-highlight.d.ts +0 -83
- package/dist/translator/search-highlight.d.ts.map +0 -1
- package/dist/translator/search-highlight.js +0 -83
- package/dist/translator/search-highlight.js.map +0 -1
- package/dist/translator/search-translator.d.ts +0 -155
- package/dist/translator/search-translator.d.ts.map +0 -1
- package/dist/translator/search-translator.js +0 -241
- package/dist/translator/search-translator.js.map +0 -1
- package/dist/translator/stages/add-fields-stage.d.ts +0 -7
- package/dist/translator/stages/add-fields-stage.d.ts.map +0 -1
- package/dist/translator/stages/add-fields-stage.js +0 -72
- package/dist/translator/stages/add-fields-stage.js.map +0 -1
- package/dist/translator/stages/bucket-stage.d.ts +0 -7
- package/dist/translator/stages/bucket-stage.d.ts.map +0 -1
- package/dist/translator/stages/bucket-stage.js +0 -87
- package/dist/translator/stages/bucket-stage.js.map +0 -1
- package/dist/translator/stages/count-stage.d.ts +0 -7
- package/dist/translator/stages/count-stage.d.ts.map +0 -1
- package/dist/translator/stages/count-stage.js +0 -12
- package/dist/translator/stages/count-stage.js.map +0 -1
- package/dist/translator/stages/expression-translator.d.ts +0 -68
- package/dist/translator/stages/expression-translator.d.ts.map +0 -1
- package/dist/translator/stages/expression-translator.js +0 -467
- package/dist/translator/stages/expression-translator.js.map +0 -1
- package/dist/translator/stages/facet-stage.d.ts +0 -13
- package/dist/translator/stages/facet-stage.d.ts.map +0 -1
- package/dist/translator/stages/facet-stage.js +0 -26
- package/dist/translator/stages/facet-stage.js.map +0 -1
- package/dist/translator/stages/fusion-stages.d.ts +0 -118
- package/dist/translator/stages/fusion-stages.d.ts.map +0 -1
- package/dist/translator/stages/fusion-stages.js +0 -201
- package/dist/translator/stages/fusion-stages.js.map +0 -1
- package/dist/translator/stages/group-stage.d.ts +0 -8
- package/dist/translator/stages/group-stage.d.ts.map +0 -1
- package/dist/translator/stages/group-stage.js +0 -123
- package/dist/translator/stages/group-stage.js.map +0 -1
- package/dist/translator/stages/index.d.ts +0 -24
- package/dist/translator/stages/index.d.ts.map +0 -1
- package/dist/translator/stages/index.js +0 -24
- package/dist/translator/stages/index.js.map +0 -1
- package/dist/translator/stages/join-optimizer.d.ts +0 -37
- package/dist/translator/stages/join-optimizer.d.ts.map +0 -1
- package/dist/translator/stages/join-optimizer.js +0 -93
- package/dist/translator/stages/join-optimizer.js.map +0 -1
- package/dist/translator/stages/limit-stage.d.ts +0 -7
- package/dist/translator/stages/limit-stage.d.ts.map +0 -1
- package/dist/translator/stages/limit-stage.js +0 -11
- package/dist/translator/stages/limit-stage.js.map +0 -1
- package/dist/translator/stages/lookup-stage.d.ts +0 -7
- package/dist/translator/stages/lookup-stage.d.ts.map +0 -1
- package/dist/translator/stages/lookup-stage.js +0 -73
- package/dist/translator/stages/lookup-stage.js.map +0 -1
- package/dist/translator/stages/match-stage.d.ts +0 -7
- package/dist/translator/stages/match-stage.d.ts.map +0 -1
- package/dist/translator/stages/match-stage.js +0 -14
- package/dist/translator/stages/match-stage.js.map +0 -1
- package/dist/translator/stages/optimizer.d.ts +0 -15
- package/dist/translator/stages/optimizer.d.ts.map +0 -1
- package/dist/translator/stages/optimizer.js +0 -249
- package/dist/translator/stages/optimizer.js.map +0 -1
- package/dist/translator/stages/parallel-facet.d.ts +0 -47
- package/dist/translator/stages/parallel-facet.d.ts.map +0 -1
- package/dist/translator/stages/parallel-facet.js +0 -57
- package/dist/translator/stages/parallel-facet.js.map +0 -1
- package/dist/translator/stages/project-stage.d.ts +0 -8
- package/dist/translator/stages/project-stage.d.ts.map +0 -1
- package/dist/translator/stages/project-stage.js +0 -145
- package/dist/translator/stages/project-stage.js.map +0 -1
- package/dist/translator/stages/search-stage.d.ts +0 -60
- package/dist/translator/stages/search-stage.d.ts.map +0 -1
- package/dist/translator/stages/search-stage.js +0 -89
- package/dist/translator/stages/search-stage.js.map +0 -1
- package/dist/translator/stages/skip-stage.d.ts +0 -7
- package/dist/translator/stages/skip-stage.d.ts.map +0 -1
- package/dist/translator/stages/skip-stage.js +0 -11
- package/dist/translator/stages/skip-stage.js.map +0 -1
- package/dist/translator/stages/sort-stage.d.ts +0 -7
- package/dist/translator/stages/sort-stage.d.ts.map +0 -1
- package/dist/translator/stages/sort-stage.js +0 -21
- package/dist/translator/stages/sort-stage.js.map +0 -1
- package/dist/translator/stages/types.d.ts +0 -136
- package/dist/translator/stages/types.d.ts.map +0 -1
- package/dist/translator/stages/types.js +0 -5
- package/dist/translator/stages/types.js.map +0 -1
- package/dist/translator/stages/unwind-stage.d.ts +0 -7
- package/dist/translator/stages/unwind-stage.d.ts.map +0 -1
- package/dist/translator/stages/unwind-stage.js +0 -61
- package/dist/translator/stages/unwind-stage.js.map +0 -1
- package/dist/translator/stages/vector-search-stage.d.ts +0 -53
- package/dist/translator/stages/vector-search-stage.d.ts.map +0 -1
- package/dist/translator/stages/vector-search-stage.js +0 -62
- package/dist/translator/stages/vector-search-stage.js.map +0 -1
- package/dist/translator/update-translator.d.ts +0 -148
- package/dist/translator/update-translator.d.ts.map +0 -1
- package/dist/translator/update-translator.js +0 -819
- package/dist/translator/update-translator.js.map +0 -1
- package/dist/translator/vector-translator.d.ts +0 -89
- package/dist/translator/vector-translator.d.ts.map +0 -1
- package/dist/translator/vector-translator.js +0 -106
- package/dist/translator/vector-translator.js.map +0 -1
- package/dist/types/env.d.ts +0 -31
- package/dist/types/env.d.ts.map +0 -1
- package/dist/types/env.js +0 -5
- package/dist/types/env.js.map +0 -1
- package/dist/types/function.d.ts +0 -65
- package/dist/types/function.d.ts.map +0 -1
- package/dist/types/function.js +0 -5
- package/dist/types/function.js.map +0 -1
- package/dist/types/index.d.ts +0 -137
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -13
- package/dist/types/index.js.map +0 -1
- package/dist/types/mongodb.d.ts +0 -258
- package/dist/types/mongodb.d.ts.map +0 -1
- package/dist/types/mongodb.js +0 -5
- package/dist/types/mongodb.js.map +0 -1
- package/dist/types/objectid.d.ts +0 -130
- package/dist/types/objectid.d.ts.map +0 -1
- package/dist/types/objectid.js +0 -314
- package/dist/types/objectid.js.map +0 -1
- package/dist/types/rpc.d.ts +0 -313
- package/dist/types/rpc.d.ts.map +0 -1
- package/dist/types/rpc.js +0 -136
- package/dist/types/rpc.js.map +0 -1
- package/dist/types/vectorize.d.ts +0 -136
- package/dist/types/vectorize.d.ts.map +0 -1
- package/dist/types/vectorize.js +0 -8
- package/dist/types/vectorize.js.map +0 -1
- package/dist/utils/sql-safety.d.ts +0 -64
- package/dist/utils/sql-safety.d.ts.map +0 -1
- package/dist/utils/sql-safety.js +0 -112
- package/dist/utils/sql-safety.js.map +0 -1
- package/dist/validation/document-validator.d.ts +0 -195
- package/dist/validation/document-validator.d.ts.map +0 -1
- package/dist/validation/document-validator.js +0 -529
- package/dist/validation/document-validator.js.map +0 -1
- package/dist/vectorize/document-serializer.d.ts +0 -119
- package/dist/vectorize/document-serializer.d.ts.map +0 -1
- package/dist/vectorize/document-serializer.js +0 -320
- package/dist/vectorize/document-serializer.js.map +0 -1
- package/dist/wire/auth/index.d.ts +0 -5
- package/dist/wire/auth/index.d.ts.map +0 -1
- package/dist/wire/auth/index.js +0 -5
- package/dist/wire/auth/index.js.map +0 -1
- package/dist/wire/auth/scram.d.ts +0 -160
- package/dist/wire/auth/scram.d.ts.map +0 -1
- package/dist/wire/auth/scram.js +0 -425
- package/dist/wire/auth/scram.js.map +0 -1
- package/dist/wire/backend/interface.d.ts +0 -168
- package/dist/wire/backend/interface.d.ts.map +0 -1
- package/dist/wire/backend/interface.js +0 -10
- package/dist/wire/backend/interface.js.map +0 -1
- package/dist/wire/backend/local-sqlite.d.ts +0 -89
- package/dist/wire/backend/local-sqlite.d.ts.map +0 -1
- package/dist/wire/backend/local-sqlite.js +0 -1002
- package/dist/wire/backend/local-sqlite.js.map +0 -1
- package/dist/wire/backend/query-router.d.ts +0 -197
- package/dist/wire/backend/query-router.d.ts.map +0 -1
- package/dist/wire/backend/query-router.js +0 -590
- package/dist/wire/backend/query-router.js.map +0 -1
- package/dist/wire/backend/validation.d.ts +0 -26
- package/dist/wire/backend/validation.d.ts.map +0 -1
- package/dist/wire/backend/validation.js +0 -79
- package/dist/wire/backend/validation.js.map +0 -1
- package/dist/wire/backend/workers-proxy.d.ts +0 -95
- package/dist/wire/backend/workers-proxy.d.ts.map +0 -1
- package/dist/wire/backend/workers-proxy.js +0 -429
- package/dist/wire/backend/workers-proxy.js.map +0 -1
- package/dist/wire/commands/admin.d.ts +0 -49
- package/dist/wire/commands/admin.d.ts.map +0 -1
- package/dist/wire/commands/admin.js +0 -272
- package/dist/wire/commands/admin.js.map +0 -1
- package/dist/wire/commands/aggregate.d.ts +0 -15
- package/dist/wire/commands/aggregate.d.ts.map +0 -1
- package/dist/wire/commands/aggregate.js +0 -98
- package/dist/wire/commands/aggregate.js.map +0 -1
- package/dist/wire/commands/auth.d.ts +0 -58
- package/dist/wire/commands/auth.d.ts.map +0 -1
- package/dist/wire/commands/auth.js +0 -158
- package/dist/wire/commands/auth.js.map +0 -1
- package/dist/wire/commands/crud.d.ts +0 -49
- package/dist/wire/commands/crud.d.ts.map +0 -1
- package/dist/wire/commands/crud.js +0 -336
- package/dist/wire/commands/crud.js.map +0 -1
- package/dist/wire/commands/hello.d.ts +0 -35
- package/dist/wire/commands/hello.d.ts.map +0 -1
- package/dist/wire/commands/hello.js +0 -204
- package/dist/wire/commands/hello.js.map +0 -1
- package/dist/wire/commands/index.d.ts +0 -24
- package/dist/wire/commands/index.d.ts.map +0 -1
- package/dist/wire/commands/index.js +0 -145
- package/dist/wire/commands/index.js.map +0 -1
- package/dist/wire/commands/router.d.ts +0 -46
- package/dist/wire/commands/router.d.ts.map +0 -1
- package/dist/wire/commands/router.js +0 -151
- package/dist/wire/commands/router.js.map +0 -1
- package/dist/wire/commands/types.d.ts +0 -51
- package/dist/wire/commands/types.d.ts.map +0 -1
- package/dist/wire/commands/types.js +0 -15
- package/dist/wire/commands/types.js.map +0 -1
- package/dist/wire/index.d.ts +0 -15
- package/dist/wire/index.d.ts.map +0 -1
- package/dist/wire/index.js +0 -19
- package/dist/wire/index.js.map +0 -1
- package/dist/wire/message.d.ts +0 -49
- package/dist/wire/message.d.ts.map +0 -1
- package/dist/wire/message.js +0 -299
- package/dist/wire/message.js.map +0 -1
- package/dist/wire/server.d.ts +0 -145
- package/dist/wire/server.d.ts.map +0 -1
- package/dist/wire/server.js +0 -284
- package/dist/wire/server.js.map +0 -1
- package/dist/wire/types.d.ts +0 -140
- package/dist/wire/types.d.ts.map +0 -1
- package/dist/wire/types.js +0 -64
- package/dist/wire/types.js.map +0 -1
- package/dist/worker.d.ts.map +0 -1
|
@@ -1,819 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* UpdateTranslator - Translates MongoDB-style update operations to SQLite SQL
|
|
3
|
-
* using json_set, json_remove, and related functions for JSON document updates.
|
|
4
|
-
*
|
|
5
|
-
* REFACTORED: Optimized with combined json_set calls, validation, and CTE-based array operations.
|
|
6
|
-
*/
|
|
7
|
-
import { validateFieldPath } from '../utils/sql-safety.js';
|
|
8
|
-
/**
|
|
9
|
-
* Parses arrayFilters option into ArrayFilter objects.
|
|
10
|
-
*
|
|
11
|
-
* @param arrayFilters - Array of filter objects from MongoDB update options
|
|
12
|
-
* @returns Parsed ArrayFilter array
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* parseArrayFilters([{ "elem.status": "pending" }])
|
|
16
|
-
* // Returns: [{ identifier: "elem", conditions: { status: "pending" } }]
|
|
17
|
-
*/
|
|
18
|
-
export function parseArrayFilters(arrayFilters) {
|
|
19
|
-
const result = [];
|
|
20
|
-
for (const filter of arrayFilters) {
|
|
21
|
-
// Each filter object should have keys like "elem.field" or "elem.field.nested"
|
|
22
|
-
// The identifier is the first part before the dot
|
|
23
|
-
const entries = Object.entries(filter);
|
|
24
|
-
if (entries.length === 0)
|
|
25
|
-
continue;
|
|
26
|
-
// Group by identifier
|
|
27
|
-
const byIdentifier = new Map();
|
|
28
|
-
for (const [key, value] of entries) {
|
|
29
|
-
const dotIndex = key.indexOf('.');
|
|
30
|
-
if (dotIndex === -1) {
|
|
31
|
-
// No dot - the key itself is the identifier with a direct condition
|
|
32
|
-
// This handles cases like { elem: { $gt: 5 } }
|
|
33
|
-
const identifier = key;
|
|
34
|
-
if (!byIdentifier.has(identifier)) {
|
|
35
|
-
byIdentifier.set(identifier, {});
|
|
36
|
-
}
|
|
37
|
-
// Store the condition directly - this is a condition on the element itself
|
|
38
|
-
byIdentifier.get(identifier)['$elemCondition'] = value;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
const identifier = key.substring(0, dotIndex);
|
|
42
|
-
const field = key.substring(dotIndex + 1);
|
|
43
|
-
if (!byIdentifier.has(identifier)) {
|
|
44
|
-
byIdentifier.set(identifier, {});
|
|
45
|
-
}
|
|
46
|
-
byIdentifier.get(identifier)[field] = value;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
for (const [identifier, conditions] of byIdentifier) {
|
|
50
|
-
result.push({ identifier, conditions });
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Parses a field path to detect positional operators.
|
|
57
|
-
* Returns information about any positional operators found.
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* parsePositionalPath("items.$.price") // { type: 'first', arrayPath: 'items' }
|
|
61
|
-
* parsePositionalPath("items.$[].qty") // { type: 'all', arrayPath: 'items' }
|
|
62
|
-
* parsePositionalPath("items.$[elem].status") // { type: 'filtered', identifier: 'elem', arrayPath: 'items' }
|
|
63
|
-
*/
|
|
64
|
-
function parsePositionalPath(path) {
|
|
65
|
-
const segments = path.split('.');
|
|
66
|
-
const operators = [];
|
|
67
|
-
let currentArrayPath = '';
|
|
68
|
-
for (let i = 0; i < segments.length; i++) {
|
|
69
|
-
const segment = segments[i];
|
|
70
|
-
if (segment === '$') {
|
|
71
|
-
// $ - positional operator for first matching element
|
|
72
|
-
operators.push({
|
|
73
|
-
type: 'first',
|
|
74
|
-
pathIndex: i,
|
|
75
|
-
arrayPath: currentArrayPath
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
else if (segment === '$[]') {
|
|
79
|
-
// $[] - update all array elements
|
|
80
|
-
operators.push({
|
|
81
|
-
type: 'all',
|
|
82
|
-
pathIndex: i,
|
|
83
|
-
arrayPath: currentArrayPath
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
else if (segment.startsWith('$[') && segment.endsWith(']')) {
|
|
87
|
-
// $[identifier] - filtered positional operator
|
|
88
|
-
const identifier = segment.slice(2, -1);
|
|
89
|
-
if (identifier) {
|
|
90
|
-
operators.push({
|
|
91
|
-
type: 'filtered',
|
|
92
|
-
identifier,
|
|
93
|
-
pathIndex: i,
|
|
94
|
-
arrayPath: currentArrayPath
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// Regular field - add to array path
|
|
100
|
-
currentArrayPath = currentArrayPath ? `${currentArrayPath}.${segment}` : segment;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return { operators, segments };
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Checks if a field path contains positional operators.
|
|
107
|
-
*/
|
|
108
|
-
function hasPositionalOperator(path) {
|
|
109
|
-
return path.includes('.$') || path.includes('.$[');
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Validates a field path segment, skipping positional operators.
|
|
113
|
-
* Positional operators ($, $[], $[identifier]) are not validated.
|
|
114
|
-
*/
|
|
115
|
-
function validateFieldPathSegment(segment) {
|
|
116
|
-
// Skip validation for positional operators
|
|
117
|
-
if (segment === '$' || segment === '$[]' || (segment.startsWith('$[') && segment.endsWith(']'))) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
// Skip validation for numeric indices
|
|
121
|
-
if (/^\d+$/.test(segment)) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
// Validate regular field names - allow alphanumeric, underscore, and hyphen
|
|
125
|
-
if (!/^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(segment) && segment !== '') {
|
|
126
|
-
throw new Error(`Invalid field path segment: ${segment}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Converts a MongoDB-style field path to a JSONPath expression.
|
|
131
|
-
* Handles nested paths and array indices.
|
|
132
|
-
*
|
|
133
|
-
* Examples:
|
|
134
|
-
* - "name" -> "$.name"
|
|
135
|
-
* - "address.city" -> "$.address.city"
|
|
136
|
-
* - "items.0.name" -> "$.items[0].name"
|
|
137
|
-
*
|
|
138
|
-
* SECURITY: Validates field path to prevent SQL injection attacks.
|
|
139
|
-
* @throws Error if field path contains invalid characters
|
|
140
|
-
*/
|
|
141
|
-
function toJsonPath(fieldPath) {
|
|
142
|
-
// Check if path has positional operators - if so, use the specialized function
|
|
143
|
-
if (hasPositionalOperator(fieldPath)) {
|
|
144
|
-
// Don't validate the whole path at once; validate segments individually
|
|
145
|
-
const parts = fieldPath.split('.');
|
|
146
|
-
for (const part of parts) {
|
|
147
|
-
validateFieldPathSegment(part);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
// Validate the entire field path to prevent SQL injection
|
|
152
|
-
validateFieldPath(fieldPath);
|
|
153
|
-
}
|
|
154
|
-
const parts = fieldPath.split('.');
|
|
155
|
-
let result = '$';
|
|
156
|
-
for (const part of parts) {
|
|
157
|
-
// Check if this part is a numeric array index
|
|
158
|
-
if (/^\d+$/.test(part)) {
|
|
159
|
-
result += `[${part}]`;
|
|
160
|
-
}
|
|
161
|
-
else if (part === '$' || part === '$[]' || (part.startsWith('$[') && part.endsWith(']'))) {
|
|
162
|
-
// Positional operators are kept as-is for later processing
|
|
163
|
-
result += `.${part}`;
|
|
164
|
-
}
|
|
165
|
-
else {
|
|
166
|
-
result += `.${part}`;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return result;
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Converts a field path with a resolved positional index to JSONPath.
|
|
173
|
-
* Used when we know the specific array index to update.
|
|
174
|
-
*
|
|
175
|
-
* @param fieldPath - The original path with positional operator
|
|
176
|
-
* @param _arrayPath - The path to the array (e.g., "items") - unused but part of API
|
|
177
|
-
* @param index - The resolved array index
|
|
178
|
-
* @returns JSONPath with the index substituted
|
|
179
|
-
*/
|
|
180
|
-
function toJsonPathWithIndex(fieldPath, _arrayPath, index) {
|
|
181
|
-
const { operators, segments } = parsePositionalPath(fieldPath);
|
|
182
|
-
if (operators.length === 0) {
|
|
183
|
-
return toJsonPath(fieldPath);
|
|
184
|
-
}
|
|
185
|
-
// Reconstruct the path with the index substituted
|
|
186
|
-
let result = '$';
|
|
187
|
-
for (let i = 0; i < segments.length; i++) {
|
|
188
|
-
const segment = segments[i];
|
|
189
|
-
if (segment === '$') {
|
|
190
|
-
result += `[${index}]`;
|
|
191
|
-
}
|
|
192
|
-
else if (/^\d+$/.test(segment)) {
|
|
193
|
-
result += `[${segment}]`;
|
|
194
|
-
}
|
|
195
|
-
else if (segment === '$[]' || (segment.startsWith('$[') && segment.endsWith(']'))) {
|
|
196
|
-
// For $[] and $[identifier], we'll handle in a different way
|
|
197
|
-
result += `.${segment}`;
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
result += `.${segment}`;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
// Export to avoid unused function warning
|
|
206
|
-
export { toJsonPathWithIndex };
|
|
207
|
-
/**
|
|
208
|
-
* Validates that a value is a valid number for arithmetic operations.
|
|
209
|
-
*/
|
|
210
|
-
function validateNumericValue(value, operator) {
|
|
211
|
-
if (typeof value !== 'number') {
|
|
212
|
-
throw new Error(`${operator} requires numeric values, got ${typeof value}`);
|
|
213
|
-
}
|
|
214
|
-
if (!Number.isFinite(value)) {
|
|
215
|
-
throw new Error(`${operator} requires finite numeric values`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Validates that an operator's fields are valid.
|
|
220
|
-
*/
|
|
221
|
-
function validateOperatorFields(operator, fields) {
|
|
222
|
-
if (typeof fields !== 'object' || fields === null || Array.isArray(fields)) {
|
|
223
|
-
throw new Error(`${operator} requires an object argument`);
|
|
224
|
-
}
|
|
225
|
-
const fieldPaths = Object.keys(fields);
|
|
226
|
-
if (fieldPaths.length === 0) {
|
|
227
|
-
throw new Error(`${operator} requires at least one field`);
|
|
228
|
-
}
|
|
229
|
-
// Validate specific operators
|
|
230
|
-
switch (operator) {
|
|
231
|
-
case '$inc':
|
|
232
|
-
case '$mul':
|
|
233
|
-
for (const [, value] of Object.entries(fields)) {
|
|
234
|
-
validateNumericValue(value, operator);
|
|
235
|
-
}
|
|
236
|
-
break;
|
|
237
|
-
case '$min':
|
|
238
|
-
case '$max':
|
|
239
|
-
for (const [, value] of Object.entries(fields)) {
|
|
240
|
-
if (value === null || value === undefined) {
|
|
241
|
-
throw new Error(`${operator} cannot use null or undefined values`);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
break;
|
|
245
|
-
case '$rename':
|
|
246
|
-
for (const [oldPath, newPath] of Object.entries(fields)) {
|
|
247
|
-
if (typeof newPath !== 'string') {
|
|
248
|
-
throw new Error(`$rename target must be a string, got ${typeof newPath}`);
|
|
249
|
-
}
|
|
250
|
-
if (oldPath === newPath) {
|
|
251
|
-
throw new Error(`$rename source and target cannot be the same: ${oldPath}`);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
break;
|
|
255
|
-
case '$pop':
|
|
256
|
-
for (const [, value] of Object.entries(fields)) {
|
|
257
|
-
if (value !== 1 && value !== -1) {
|
|
258
|
-
throw new Error(`$pop requires 1 (last) or -1 (first), got ${value}`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
break;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Detects conflicts between update operators.
|
|
266
|
-
* MongoDB does not allow updating the same field with multiple operators.
|
|
267
|
-
*/
|
|
268
|
-
function detectConflicts(update) {
|
|
269
|
-
const updatedPaths = new Map(); // path -> operator
|
|
270
|
-
for (const [operator, fields] of Object.entries(update)) {
|
|
271
|
-
if (!operator.startsWith('$'))
|
|
272
|
-
continue;
|
|
273
|
-
if (typeof fields !== 'object' || fields === null)
|
|
274
|
-
continue;
|
|
275
|
-
for (const path of Object.keys(fields)) {
|
|
276
|
-
// For $rename, check both source and target
|
|
277
|
-
if (operator === '$rename') {
|
|
278
|
-
const targetPath = fields[path];
|
|
279
|
-
if (updatedPaths.has(path)) {
|
|
280
|
-
throw new Error(`Conflicting update: ${path} is modified by both ${updatedPaths.get(path)} and ${operator}`);
|
|
281
|
-
}
|
|
282
|
-
if (updatedPaths.has(targetPath)) {
|
|
283
|
-
throw new Error(`Conflicting update: ${targetPath} is modified by both ${updatedPaths.get(targetPath)} and ${operator}`);
|
|
284
|
-
}
|
|
285
|
-
updatedPaths.set(path, operator);
|
|
286
|
-
updatedPaths.set(targetPath, operator);
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
// Check for conflicts with existing updates
|
|
290
|
-
if (updatedPaths.has(path)) {
|
|
291
|
-
const existingOp = updatedPaths.get(path);
|
|
292
|
-
// Allow $min and $max on same field as they're complementary
|
|
293
|
-
if (!((operator === '$min' && existingOp === '$max') ||
|
|
294
|
-
(operator === '$max' && existingOp === '$min'))) {
|
|
295
|
-
throw new Error(`Conflicting update: ${path} is modified by both ${existingOp} and ${operator}`);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
updatedPaths.set(path, operator);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Creates a SQL value expression for a given value.
|
|
305
|
-
* Returns the SQL fragment and any parameters needed.
|
|
306
|
-
*/
|
|
307
|
-
function createValueExpression(value) {
|
|
308
|
-
if (value === null) {
|
|
309
|
-
return { sql: "json('null')", params: [] };
|
|
310
|
-
}
|
|
311
|
-
if (typeof value === 'boolean') {
|
|
312
|
-
return { sql: 'json(?)', params: [value.toString()] };
|
|
313
|
-
}
|
|
314
|
-
if (typeof value === 'object') {
|
|
315
|
-
return { sql: 'json(?)', params: [JSON.stringify(value)] };
|
|
316
|
-
}
|
|
317
|
-
return { sql: '?', params: [value] };
|
|
318
|
-
}
|
|
319
|
-
export class UpdateTranslator {
|
|
320
|
-
static SUPPORTED_OPERATORS = new Set([
|
|
321
|
-
'$set', '$unset', '$inc', '$mul', '$min', '$max', '$rename',
|
|
322
|
-
'$push', '$pull', '$addToSet', '$pop', '$bit', '$pullAll', '$setOnInsert'
|
|
323
|
-
]);
|
|
324
|
-
// Operator processing order - ensures proper nesting and conflict resolution
|
|
325
|
-
// $setOnInsert is handled specially and not processed here (it requires upsert context)
|
|
326
|
-
static OPERATOR_ORDER = [
|
|
327
|
-
'$rename', '$unset', '$set', '$setOnInsert', '$inc', '$mul', '$min', '$max', '$bit',
|
|
328
|
-
'$push', '$addToSet', '$pull', '$pullAll', '$pop'
|
|
329
|
-
];
|
|
330
|
-
/**
|
|
331
|
-
* Translates a MongoDB-style update object to SQLite SQL.
|
|
332
|
-
* Returns the SQL expression and parameters for updating the data column.
|
|
333
|
-
*
|
|
334
|
-
* @param update - MongoDB update document with operators like $set, $inc, etc.
|
|
335
|
-
* @returns Translated SQL expression and parameters
|
|
336
|
-
* @throws Error if operators are invalid or conflicting
|
|
337
|
-
*/
|
|
338
|
-
translate(update) {
|
|
339
|
-
const operators = Object.keys(update);
|
|
340
|
-
// Handle empty update - return data as-is
|
|
341
|
-
if (operators.length === 0) {
|
|
342
|
-
return { sql: 'data', params: [] };
|
|
343
|
-
}
|
|
344
|
-
// Validate all operators
|
|
345
|
-
for (const op of operators) {
|
|
346
|
-
if (!op.startsWith('$')) {
|
|
347
|
-
throw new Error(`Invalid update operator: ${op}. Update operators must start with $`);
|
|
348
|
-
}
|
|
349
|
-
if (!UpdateTranslator.SUPPORTED_OPERATORS.has(op)) {
|
|
350
|
-
throw new Error(`Unknown update operator: ${op}`);
|
|
351
|
-
}
|
|
352
|
-
validateOperatorFields(op, update[op]);
|
|
353
|
-
}
|
|
354
|
-
// Detect conflicts between operators
|
|
355
|
-
detectConflicts(update);
|
|
356
|
-
// Process updates in defined order
|
|
357
|
-
let currentSql = 'data';
|
|
358
|
-
let currentParams = [];
|
|
359
|
-
for (const op of UpdateTranslator.OPERATOR_ORDER) {
|
|
360
|
-
if (update[op]) {
|
|
361
|
-
const result = this.translateOperator(op, update[op], currentSql, currentParams);
|
|
362
|
-
currentSql = result.sql;
|
|
363
|
-
currentParams = result.params;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
return { sql: currentSql, params: currentParams };
|
|
367
|
-
}
|
|
368
|
-
translateOperator(operator, fields, baseSql, baseParams) {
|
|
369
|
-
switch (operator) {
|
|
370
|
-
case '$set':
|
|
371
|
-
return this.translateSet(fields, baseSql, baseParams);
|
|
372
|
-
case '$unset':
|
|
373
|
-
return this.translateUnset(fields, baseSql, baseParams);
|
|
374
|
-
case '$inc':
|
|
375
|
-
return this.translateInc(fields, baseSql, baseParams);
|
|
376
|
-
case '$mul':
|
|
377
|
-
return this.translateMul(fields, baseSql, baseParams);
|
|
378
|
-
case '$min':
|
|
379
|
-
return this.translateMin(fields, baseSql, baseParams);
|
|
380
|
-
case '$max':
|
|
381
|
-
return this.translateMax(fields, baseSql, baseParams);
|
|
382
|
-
case '$rename':
|
|
383
|
-
return this.translateRename(fields, baseSql, baseParams);
|
|
384
|
-
case '$push':
|
|
385
|
-
return this.translatePush(fields, baseSql, baseParams);
|
|
386
|
-
case '$pull':
|
|
387
|
-
return this.translatePull(fields, baseSql, baseParams);
|
|
388
|
-
case '$addToSet':
|
|
389
|
-
return this.translateAddToSet(fields, baseSql, baseParams);
|
|
390
|
-
case '$pop':
|
|
391
|
-
return this.translatePop(fields, baseSql, baseParams);
|
|
392
|
-
case '$bit':
|
|
393
|
-
// $bit is not commonly used and not yet implemented
|
|
394
|
-
throw new Error('$bit operator is not yet implemented');
|
|
395
|
-
case '$pullAll':
|
|
396
|
-
// $pullAll removes all matching values - can use same logic as $pull with $in
|
|
397
|
-
throw new Error('$pullAll operator is not yet implemented');
|
|
398
|
-
case '$setOnInsert':
|
|
399
|
-
// $setOnInsert only applies during upserts - just treat as $set for now
|
|
400
|
-
return this.translateSet(fields, baseSql, baseParams);
|
|
401
|
-
default:
|
|
402
|
-
throw new Error(`Unsupported operator: ${operator}`);
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
// ============================================================
|
|
406
|
-
// FIELD UPDATE OPERATORS
|
|
407
|
-
// ============================================================
|
|
408
|
-
/**
|
|
409
|
-
* Translates $set operator using optimized multi-path json_set.
|
|
410
|
-
*
|
|
411
|
-
* OPTIMIZATION: SQLite's json_set supports multiple path-value pairs in a single call:
|
|
412
|
-
* json_set(data, '$.a', 1, '$.b', 2) instead of json_set(json_set(data, '$.a', 1), '$.b', 2)
|
|
413
|
-
*/
|
|
414
|
-
translateSet(fields, baseSql, baseParams) {
|
|
415
|
-
const entries = Object.entries(fields);
|
|
416
|
-
if (entries.length === 0) {
|
|
417
|
-
return { sql: baseSql, params: baseParams };
|
|
418
|
-
}
|
|
419
|
-
// Build optimized multi-path json_set
|
|
420
|
-
const pathValuePairs = [];
|
|
421
|
-
const params = [...baseParams];
|
|
422
|
-
for (const [path, value] of entries) {
|
|
423
|
-
const jsonPath = toJsonPath(path);
|
|
424
|
-
const valueExpr = createValueExpression(value);
|
|
425
|
-
pathValuePairs.push(`'${jsonPath}'`);
|
|
426
|
-
pathValuePairs.push(valueExpr.sql);
|
|
427
|
-
params.push(...valueExpr.params);
|
|
428
|
-
}
|
|
429
|
-
return {
|
|
430
|
-
sql: `json_set(${baseSql}, ${pathValuePairs.join(', ')})`,
|
|
431
|
-
params
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Translates $unset operator using optimized multi-path json_remove.
|
|
436
|
-
*
|
|
437
|
-
* OPTIMIZATION: SQLite's json_remove supports multiple paths in a single call.
|
|
438
|
-
*/
|
|
439
|
-
translateUnset(fields, baseSql, baseParams) {
|
|
440
|
-
const paths = Object.keys(fields);
|
|
441
|
-
if (paths.length === 0) {
|
|
442
|
-
return { sql: baseSql, params: baseParams };
|
|
443
|
-
}
|
|
444
|
-
// Build optimized multi-path json_remove
|
|
445
|
-
const jsonPaths = paths.map(p => `'${toJsonPath(p)}'`).join(', ');
|
|
446
|
-
return {
|
|
447
|
-
sql: `json_remove(${baseSql}, ${jsonPaths})`,
|
|
448
|
-
params: baseParams
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Translates $inc operator to json_set with addition.
|
|
453
|
-
* Uses COALESCE to handle missing fields (defaulting to 0).
|
|
454
|
-
*/
|
|
455
|
-
translateInc(fields, baseSql, baseParams) {
|
|
456
|
-
let sql = baseSql;
|
|
457
|
-
let params = [...baseParams];
|
|
458
|
-
for (const [path, increment] of Object.entries(fields)) {
|
|
459
|
-
const jsonPath = toJsonPath(path);
|
|
460
|
-
sql = `json_set(${sql}, '${jsonPath}', COALESCE(json_extract(data, '${jsonPath}'), 0) + ?)`;
|
|
461
|
-
params.push(increment);
|
|
462
|
-
}
|
|
463
|
-
return { sql, params };
|
|
464
|
-
}
|
|
465
|
-
/**
|
|
466
|
-
* Translates $mul operator to json_set with multiplication.
|
|
467
|
-
* Uses COALESCE to handle missing fields (defaulting to 0, which means result is 0).
|
|
468
|
-
*/
|
|
469
|
-
translateMul(fields, baseSql, baseParams) {
|
|
470
|
-
let sql = baseSql;
|
|
471
|
-
let params = [...baseParams];
|
|
472
|
-
for (const [path, multiplier] of Object.entries(fields)) {
|
|
473
|
-
const jsonPath = toJsonPath(path);
|
|
474
|
-
sql = `json_set(${sql}, '${jsonPath}', COALESCE(json_extract(data, '${jsonPath}'), 0) * ?)`;
|
|
475
|
-
params.push(multiplier);
|
|
476
|
-
}
|
|
477
|
-
return { sql, params };
|
|
478
|
-
}
|
|
479
|
-
/**
|
|
480
|
-
* Translates $min operator to conditional update.
|
|
481
|
-
* Sets the field to the smaller of current value or specified value.
|
|
482
|
-
* If field doesn't exist, sets it to the specified value.
|
|
483
|
-
*/
|
|
484
|
-
translateMin(fields, baseSql, baseParams) {
|
|
485
|
-
let sql = baseSql;
|
|
486
|
-
let params = [...baseParams];
|
|
487
|
-
for (const [path, value] of Object.entries(fields)) {
|
|
488
|
-
const jsonPath = toJsonPath(path);
|
|
489
|
-
sql = `json_set(${sql}, '${jsonPath}', CASE WHEN json_extract(data, '${jsonPath}') IS NULL OR ? < json_extract(data, '${jsonPath}') THEN ? ELSE json_extract(data, '${jsonPath}') END)`;
|
|
490
|
-
params.push(value, value);
|
|
491
|
-
}
|
|
492
|
-
return { sql, params };
|
|
493
|
-
}
|
|
494
|
-
/**
|
|
495
|
-
* Translates $max operator to conditional update.
|
|
496
|
-
* Sets the field to the larger of current value or specified value.
|
|
497
|
-
* If field doesn't exist, sets it to the specified value.
|
|
498
|
-
*/
|
|
499
|
-
translateMax(fields, baseSql, baseParams) {
|
|
500
|
-
let sql = baseSql;
|
|
501
|
-
let params = [...baseParams];
|
|
502
|
-
for (const [path, value] of Object.entries(fields)) {
|
|
503
|
-
const jsonPath = toJsonPath(path);
|
|
504
|
-
sql = `json_set(${sql}, '${jsonPath}', CASE WHEN json_extract(data, '${jsonPath}') IS NULL OR ? > json_extract(data, '${jsonPath}') THEN ? ELSE json_extract(data, '${jsonPath}') END)`;
|
|
505
|
-
params.push(value, value);
|
|
506
|
-
}
|
|
507
|
-
return { sql, params };
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Translates $rename operator to json_set + json_remove combination.
|
|
511
|
-
* Moves a field from one location to another.
|
|
512
|
-
*/
|
|
513
|
-
translateRename(fields, baseSql, baseParams) {
|
|
514
|
-
let sql = baseSql;
|
|
515
|
-
const params = [...baseParams];
|
|
516
|
-
for (const [oldPath, newPath] of Object.entries(fields)) {
|
|
517
|
-
const oldJsonPath = toJsonPath(oldPath);
|
|
518
|
-
const newJsonPath = toJsonPath(newPath);
|
|
519
|
-
// Extract value, remove old path, set new path
|
|
520
|
-
sql = `json_set(json_remove(${sql}, '${oldJsonPath}'), '${newJsonPath}', json_extract(data, '${oldJsonPath}'))`;
|
|
521
|
-
}
|
|
522
|
-
return { sql, params };
|
|
523
|
-
}
|
|
524
|
-
// ============================================================
|
|
525
|
-
// ARRAY UPDATE OPERATORS
|
|
526
|
-
// ============================================================
|
|
527
|
-
/**
|
|
528
|
-
* Translates $push operator to append values to an array.
|
|
529
|
-
* Supports $each and $slice modifiers.
|
|
530
|
-
*/
|
|
531
|
-
translatePush(fields, baseSql, baseParams) {
|
|
532
|
-
let sql = baseSql;
|
|
533
|
-
let params = [...baseParams];
|
|
534
|
-
for (const [path, value] of Object.entries(fields)) {
|
|
535
|
-
const jsonPath = toJsonPath(path);
|
|
536
|
-
// Check for $each and $slice modifiers
|
|
537
|
-
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
538
|
-
const modifiers = value;
|
|
539
|
-
if ('$each' in modifiers) {
|
|
540
|
-
const result = this.translatePushEach(path, modifiers, sql, params);
|
|
541
|
-
sql = result.sql;
|
|
542
|
-
params = result.params;
|
|
543
|
-
continue;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
// Simple push - append single value
|
|
547
|
-
const valueExpr = createValueExpression(value);
|
|
548
|
-
sql = `json_set(${sql}, '${jsonPath}', json_insert(COALESCE(json_extract(data, '${jsonPath}'), '[]'), '$[#]', ${valueExpr.sql}))`;
|
|
549
|
-
params.push(...valueExpr.params);
|
|
550
|
-
}
|
|
551
|
-
return { sql, params };
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Handles $push with $each modifier for batch appending.
|
|
555
|
-
* Uses CTE for efficient array building when $slice is present.
|
|
556
|
-
*/
|
|
557
|
-
translatePushEach(path, modifiers, baseSql, baseParams) {
|
|
558
|
-
const jsonPath = toJsonPath(path);
|
|
559
|
-
const values = modifiers.$each;
|
|
560
|
-
const slice = modifiers.$slice;
|
|
561
|
-
if (values.length === 0) {
|
|
562
|
-
// No values to push - ensure array exists
|
|
563
|
-
if (slice !== undefined) {
|
|
564
|
-
return this.applySliceWithCTE(baseSql, jsonPath, slice, baseParams);
|
|
565
|
-
}
|
|
566
|
-
return {
|
|
567
|
-
sql: `json_set(${baseSql}, '${jsonPath}', COALESCE(json_extract(data, '${jsonPath}'), '[]'))`,
|
|
568
|
-
params: baseParams
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
let params = [...baseParams];
|
|
572
|
-
// Build nested json_insert calls for batch append
|
|
573
|
-
let insertChain = `COALESCE(json_extract(data, '${jsonPath}'), '[]')`;
|
|
574
|
-
for (const value of values) {
|
|
575
|
-
const valueExpr = createValueExpression(value);
|
|
576
|
-
insertChain = `json_insert(${insertChain}, '$[#]', ${valueExpr.sql})`;
|
|
577
|
-
params.push(...valueExpr.params);
|
|
578
|
-
}
|
|
579
|
-
let sql = `json_set(${baseSql}, '${jsonPath}', ${insertChain})`;
|
|
580
|
-
// Apply $slice with CTE optimization
|
|
581
|
-
if (slice !== undefined) {
|
|
582
|
-
return this.applySliceWithCTE(sql, jsonPath, slice, params);
|
|
583
|
-
}
|
|
584
|
-
return { sql, params };
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* Applies $slice modifier using CTE for efficient array slicing.
|
|
588
|
-
* CTE provides better performance for large arrays.
|
|
589
|
-
*/
|
|
590
|
-
applySliceWithCTE(baseSql, jsonPath, slice, baseParams) {
|
|
591
|
-
if (slice === 0) {
|
|
592
|
-
// Empty array result
|
|
593
|
-
return {
|
|
594
|
-
sql: `json_set(${baseSql}, '${jsonPath}', json('[]'))`,
|
|
595
|
-
params: baseParams
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
const params = [...baseParams];
|
|
599
|
-
if (slice > 0) {
|
|
600
|
-
// Keep first N elements using CTE
|
|
601
|
-
return {
|
|
602
|
-
sql: `json_set(${baseSql}, '${jsonPath}', (
|
|
603
|
-
WITH array_elements AS (
|
|
604
|
-
SELECT value, CAST(key AS INTEGER) as idx
|
|
605
|
-
FROM json_each(json_extract(${baseSql}, '${jsonPath}'))
|
|
606
|
-
)
|
|
607
|
-
SELECT COALESCE(json_group_array(value), '[]')
|
|
608
|
-
FROM (
|
|
609
|
-
SELECT value FROM array_elements
|
|
610
|
-
ORDER BY idx
|
|
611
|
-
LIMIT ${slice}
|
|
612
|
-
)
|
|
613
|
-
))`,
|
|
614
|
-
params
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
else {
|
|
618
|
-
// Keep last N elements (slice is negative) using CTE
|
|
619
|
-
const limit = Math.abs(slice);
|
|
620
|
-
return {
|
|
621
|
-
sql: `json_set(${baseSql}, '${jsonPath}', (
|
|
622
|
-
WITH array_elements AS (
|
|
623
|
-
SELECT value, CAST(key AS INTEGER) as idx
|
|
624
|
-
FROM json_each(json_extract(${baseSql}, '${jsonPath}'))
|
|
625
|
-
),
|
|
626
|
-
total AS (SELECT COUNT(*) as cnt FROM array_elements),
|
|
627
|
-
filtered AS (
|
|
628
|
-
SELECT value, idx FROM array_elements, total
|
|
629
|
-
WHERE idx >= (cnt - ${limit})
|
|
630
|
-
)
|
|
631
|
-
SELECT COALESCE(json_group_array(value), '[]')
|
|
632
|
-
FROM (SELECT value FROM filtered ORDER BY idx)
|
|
633
|
-
))`,
|
|
634
|
-
params
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Translates $pull operator to remove matching elements.
|
|
640
|
-
* Uses CTE for efficient filtering.
|
|
641
|
-
*/
|
|
642
|
-
translatePull(fields, baseSql, baseParams) {
|
|
643
|
-
let sql = baseSql;
|
|
644
|
-
let params = [...baseParams];
|
|
645
|
-
for (const [path, condition] of Object.entries(fields)) {
|
|
646
|
-
const jsonPath = toJsonPath(path);
|
|
647
|
-
// Check if condition is a simple value or a query
|
|
648
|
-
if (typeof condition === 'object' && condition !== null && !Array.isArray(condition)) {
|
|
649
|
-
// Query condition - use CTE for complex filtering
|
|
650
|
-
const result = this.translatePullWithQueryCTE(path, condition, sql, params);
|
|
651
|
-
sql = result.sql;
|
|
652
|
-
params = result.params;
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
// Simple value match using CTE
|
|
656
|
-
sql = `json_set(${sql}, '${jsonPath}', (
|
|
657
|
-
WITH array_elements AS (
|
|
658
|
-
SELECT value, CAST(key AS INTEGER) as idx
|
|
659
|
-
FROM json_each(json_extract(data, '${jsonPath}'))
|
|
660
|
-
)
|
|
661
|
-
SELECT COALESCE(json_group_array(value), '[]')
|
|
662
|
-
FROM (
|
|
663
|
-
SELECT value FROM array_elements
|
|
664
|
-
WHERE value != json(?)
|
|
665
|
-
ORDER BY idx
|
|
666
|
-
)
|
|
667
|
-
))`;
|
|
668
|
-
// JSON stringify for comparison
|
|
669
|
-
params.push(JSON.stringify(condition));
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
return { sql, params };
|
|
673
|
-
}
|
|
674
|
-
/**
|
|
675
|
-
* Handles $pull with query conditions using CTE.
|
|
676
|
-
*/
|
|
677
|
-
translatePullWithQueryCTE(path, condition, baseSql, baseParams) {
|
|
678
|
-
const jsonPath = toJsonPath(path);
|
|
679
|
-
const params = [...baseParams];
|
|
680
|
-
// Build WHERE clause for the condition
|
|
681
|
-
const conditions = [];
|
|
682
|
-
for (const [field, value] of Object.entries(condition)) {
|
|
683
|
-
// Validate field name to prevent SQL injection
|
|
684
|
-
validateFieldPath(field);
|
|
685
|
-
if (typeof value === 'object' && value !== null) {
|
|
686
|
-
// Handle operators like $gte, $lte, etc.
|
|
687
|
-
for (const [op, opValue] of Object.entries(value)) {
|
|
688
|
-
const sqlOp = this.mongoOpToSql(op);
|
|
689
|
-
conditions.push(`json_extract(value, '$.${field}') ${sqlOp} ?`);
|
|
690
|
-
params.push(opValue);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
else {
|
|
694
|
-
conditions.push(`json_extract(value, '$.${field}') = ?`);
|
|
695
|
-
params.push(value);
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
const whereClause = conditions.length > 0 ? `NOT (${conditions.join(' AND ')})` : '1=1';
|
|
699
|
-
return {
|
|
700
|
-
sql: `json_set(${baseSql}, '${jsonPath}', (
|
|
701
|
-
WITH array_elements AS (
|
|
702
|
-
SELECT value, CAST(key AS INTEGER) as idx
|
|
703
|
-
FROM json_each(json_extract(data, '${jsonPath}'))
|
|
704
|
-
)
|
|
705
|
-
SELECT COALESCE(json_group_array(value), '[]')
|
|
706
|
-
FROM (
|
|
707
|
-
SELECT value FROM array_elements
|
|
708
|
-
WHERE ${whereClause}
|
|
709
|
-
ORDER BY idx
|
|
710
|
-
)
|
|
711
|
-
))`,
|
|
712
|
-
params
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
mongoOpToSql(op) {
|
|
716
|
-
switch (op) {
|
|
717
|
-
case '$eq': return '=';
|
|
718
|
-
case '$ne': return '!=';
|
|
719
|
-
case '$gt': return '>';
|
|
720
|
-
case '$gte': return '>=';
|
|
721
|
-
case '$lt': return '<';
|
|
722
|
-
case '$lte': return '<=';
|
|
723
|
-
default: throw new Error(`Unsupported operator in $pull: ${op}`);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* Translates $addToSet operator to push if value doesn't exist.
|
|
728
|
-
* Uses CTE for efficient uniqueness check.
|
|
729
|
-
*/
|
|
730
|
-
translateAddToSet(fields, baseSql, baseParams) {
|
|
731
|
-
let sql = baseSql;
|
|
732
|
-
let params = [...baseParams];
|
|
733
|
-
for (const [path, value] of Object.entries(fields)) {
|
|
734
|
-
const jsonPath = toJsonPath(path);
|
|
735
|
-
// Check for $each modifier
|
|
736
|
-
if (value && typeof value === 'object' && !Array.isArray(value) && '$each' in value) {
|
|
737
|
-
const values = value.$each;
|
|
738
|
-
for (const v of values) {
|
|
739
|
-
const result = this.translateAddToSetSingleWithCTE(jsonPath, v, sql, params);
|
|
740
|
-
sql = result.sql;
|
|
741
|
-
params = result.params;
|
|
742
|
-
}
|
|
743
|
-
continue;
|
|
744
|
-
}
|
|
745
|
-
const result = this.translateAddToSetSingleWithCTE(jsonPath, value, sql, params);
|
|
746
|
-
sql = result.sql;
|
|
747
|
-
params = result.params;
|
|
748
|
-
}
|
|
749
|
-
return { sql, params };
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Single value $addToSet using CTE for uniqueness check.
|
|
753
|
-
*/
|
|
754
|
-
translateAddToSetSingleWithCTE(jsonPath, value, baseSql, baseParams) {
|
|
755
|
-
const params = [...baseParams];
|
|
756
|
-
const valueExpr = createValueExpression(value);
|
|
757
|
-
// Check if value exists in array, if not add it
|
|
758
|
-
const sql = `json_set(${baseSql}, '${jsonPath}',
|
|
759
|
-
CASE
|
|
760
|
-
WHEN EXISTS (
|
|
761
|
-
SELECT 1 FROM json_each(COALESCE(json_extract(data, '${jsonPath}'), '[]'))
|
|
762
|
-
WHERE value = json(?)
|
|
763
|
-
)
|
|
764
|
-
THEN COALESCE(json_extract(data, '${jsonPath}'), '[]')
|
|
765
|
-
ELSE json_insert(COALESCE(json_extract(data, '${jsonPath}'), '[]'), '$[#]', ${valueExpr.sql})
|
|
766
|
-
END
|
|
767
|
-
)`;
|
|
768
|
-
// First param is for the EXISTS check (needs JSON stringification)
|
|
769
|
-
params.push(JSON.stringify(value));
|
|
770
|
-
// Subsequent params are for the value expression
|
|
771
|
-
params.push(...valueExpr.params);
|
|
772
|
-
return { sql, params };
|
|
773
|
-
}
|
|
774
|
-
/**
|
|
775
|
-
* Translates $pop operator to remove first or last element.
|
|
776
|
-
* Uses CTE for efficient element removal.
|
|
777
|
-
*/
|
|
778
|
-
translatePop(fields, baseSql, baseParams) {
|
|
779
|
-
let sql = baseSql;
|
|
780
|
-
const params = [...baseParams];
|
|
781
|
-
for (const [path, direction] of Object.entries(fields)) {
|
|
782
|
-
const jsonPath = toJsonPath(path);
|
|
783
|
-
const dir = direction;
|
|
784
|
-
if (dir === 1) {
|
|
785
|
-
// Remove last element using CTE
|
|
786
|
-
sql = `json_set(${sql}, '${jsonPath}', (
|
|
787
|
-
WITH array_elements AS (
|
|
788
|
-
SELECT value, CAST(key AS INTEGER) as idx
|
|
789
|
-
FROM json_each(COALESCE(json_extract(data, '${jsonPath}'), '[]'))
|
|
790
|
-
),
|
|
791
|
-
total AS (SELECT COUNT(*) as cnt FROM array_elements)
|
|
792
|
-
SELECT COALESCE(json_group_array(value), '[]')
|
|
793
|
-
FROM (
|
|
794
|
-
SELECT value FROM array_elements, total
|
|
795
|
-
WHERE idx < cnt - 1
|
|
796
|
-
ORDER BY idx
|
|
797
|
-
)
|
|
798
|
-
))`;
|
|
799
|
-
}
|
|
800
|
-
else {
|
|
801
|
-
// Remove first element using CTE
|
|
802
|
-
sql = `json_set(${sql}, '${jsonPath}', (
|
|
803
|
-
WITH array_elements AS (
|
|
804
|
-
SELECT value, CAST(key AS INTEGER) as idx
|
|
805
|
-
FROM json_each(COALESCE(json_extract(data, '${jsonPath}'), '[]'))
|
|
806
|
-
)
|
|
807
|
-
SELECT COALESCE(json_group_array(value), '[]')
|
|
808
|
-
FROM (
|
|
809
|
-
SELECT value FROM array_elements
|
|
810
|
-
WHERE idx > 0
|
|
811
|
-
ORDER BY idx
|
|
812
|
-
)
|
|
813
|
-
))`;
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
return { sql, params };
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
//# sourceMappingURL=update-translator.js.map
|