@lancedb/lancedb 0.7.1 → 0.9.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.
Files changed (92) hide show
  1. package/dist/arrow.d.ts +2 -3
  2. package/dist/arrow.js +2 -27
  3. package/dist/connection.d.ts +9 -0
  4. package/dist/connection.js +16 -2
  5. package/dist/embedding/embedding_function.d.ts +11 -0
  6. package/dist/embedding/embedding_function.js +28 -7
  7. package/dist/embedding/index.d.ts +2 -1
  8. package/dist/embedding/index.js +7 -6
  9. package/dist/embedding/openai.d.ts +1 -1
  10. package/dist/embedding/registry.d.ts +9 -7
  11. package/dist/embedding/registry.js +24 -6
  12. package/dist/embedding/transformers.d.ts +37 -0
  13. package/dist/embedding/transformers.js +147 -0
  14. package/dist/index.d.ts +1 -1
  15. package/dist/query.js +15 -9
  16. package/dist/remote/client.d.ts +1 -1
  17. package/dist/remote/client.js +6 -8
  18. package/dist/remote/connection.d.ts +2 -3
  19. package/dist/remote/connection.js +2 -2
  20. package/dist/sanitize.js +4 -2
  21. package/dist/table.d.ts +3 -0
  22. package/dist/table.js +1 -1
  23. package/package.json +17 -13
  24. package/Cargo.toml +0 -28
  25. package/biome.json +0 -158
  26. package/build.rs +0 -5
  27. package/dist/native.d.ts +0 -208
  28. package/examples/ann_indexes.ts +0 -49
  29. package/examples/basic.ts +0 -149
  30. package/examples/embedding.ts +0 -83
  31. package/examples/filtering.ts +0 -34
  32. package/examples/jsconfig.json +0 -27
  33. package/examples/package-lock.json +0 -79
  34. package/examples/package.json +0 -18
  35. package/examples/search.ts +0 -37
  36. package/jest.config.js +0 -7
  37. package/lancedb/arrow.ts +0 -947
  38. package/lancedb/connection.ts +0 -333
  39. package/lancedb/embedding/embedding_function.ts +0 -194
  40. package/lancedb/embedding/index.ts +0 -113
  41. package/lancedb/embedding/openai.ts +0 -113
  42. package/lancedb/embedding/registry.ts +0 -188
  43. package/lancedb/index.ts +0 -142
  44. package/lancedb/indices.ts +0 -203
  45. package/lancedb/merge.ts +0 -70
  46. package/lancedb/query.ts +0 -507
  47. package/lancedb/remote/client.ts +0 -221
  48. package/lancedb/remote/connection.ts +0 -201
  49. package/lancedb/remote/index.ts +0 -3
  50. package/lancedb/remote/table.ts +0 -226
  51. package/lancedb/sanitize.ts +0 -588
  52. package/lancedb/table.ts +0 -669
  53. package/lancedb/util.ts +0 -69
  54. package/native.d.ts +0 -208
  55. package/nodejs-artifacts/arrow.d.ts +0 -250
  56. package/nodejs-artifacts/arrow.js +0 -768
  57. package/nodejs-artifacts/connection.d.ts +0 -171
  58. package/nodejs-artifacts/connection.js +0 -135
  59. package/nodejs-artifacts/embedding/embedding_function.d.ts +0 -79
  60. package/nodejs-artifacts/embedding/embedding_function.js +0 -112
  61. package/nodejs-artifacts/embedding/index.d.ts +0 -28
  62. package/nodejs-artifacts/embedding/index.js +0 -114
  63. package/nodejs-artifacts/embedding/openai.d.ts +0 -18
  64. package/nodejs-artifacts/embedding/openai.js +0 -105
  65. package/nodejs-artifacts/embedding/registry.d.ts +0 -53
  66. package/nodejs-artifacts/embedding/registry.js +0 -127
  67. package/nodejs-artifacts/index.d.ts +0 -55
  68. package/nodejs-artifacts/index.js +0 -57
  69. package/nodejs-artifacts/indices.d.ts +0 -165
  70. package/nodejs-artifacts/indices.js +0 -71
  71. package/nodejs-artifacts/merge.d.ts +0 -54
  72. package/nodejs-artifacts/merge.js +0 -64
  73. package/nodejs-artifacts/native.d.ts +0 -208
  74. package/nodejs-artifacts/native.js +0 -330
  75. package/nodejs-artifacts/query.d.ts +0 -283
  76. package/nodejs-artifacts/query.js +0 -448
  77. package/nodejs-artifacts/remote/client.d.ts +0 -28
  78. package/nodejs-artifacts/remote/client.js +0 -172
  79. package/nodejs-artifacts/remote/connection.d.ts +0 -25
  80. package/nodejs-artifacts/remote/connection.js +0 -110
  81. package/nodejs-artifacts/remote/index.d.ts +0 -3
  82. package/nodejs-artifacts/remote/index.js +0 -9
  83. package/nodejs-artifacts/remote/table.d.ts +0 -42
  84. package/nodejs-artifacts/remote/table.js +0 -179
  85. package/nodejs-artifacts/sanitize.d.ts +0 -31
  86. package/nodejs-artifacts/sanitize.js +0 -436
  87. package/nodejs-artifacts/table.d.ts +0 -395
  88. package/nodejs-artifacts/table.js +0 -230
  89. package/nodejs-artifacts/util.d.ts +0 -14
  90. package/nodejs-artifacts/util.js +0 -65
  91. package/tsconfig.json +0 -25
  92. package/typedoc.json +0 -10
@@ -1,436 +0,0 @@
1
- "use strict";
2
- // Copyright 2023 LanceDB Developers.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.sanitizeTable = exports.sanitizeSchema = exports.sanitizeField = exports.sanitizeType = exports.sanitizeDictionary = exports.sanitizeDuration = exports.sanitizeMap = exports.sanitizeFixedSizeList = exports.sanitizeFixedSizeBinary = exports.sanitizeTypedUnion = exports.sanitizeUnion = exports.sanitizeStruct = exports.sanitizeList = exports.sanitizeInterval = exports.sanitizeTypedTimestamp = exports.sanitizeTimestamp = exports.sanitizeTime = exports.sanitizeDate = exports.sanitizeDecimal = exports.sanitizeFloat = exports.sanitizeInt = exports.sanitizeMetadata = void 0;
17
- // The utilities in this file help sanitize data from the user's arrow
18
- // library into the types expected by vectordb's arrow library. Node
19
- // generally allows for mulitple versions of the same library (and sometimes
20
- // even multiple copies of the same version) to be installed at the same
21
- // time. However, arrow-js uses instanceof which expected that the input
22
- // comes from the exact same library instance. This is not always the case
23
- // and so we must sanitize the input to ensure that it is compatible.
24
- const apache_arrow_1 = require("apache-arrow");
25
- const arrow_1 = require("./arrow");
26
- function sanitizeMetadata(metadataLike) {
27
- if (metadataLike === undefined || metadataLike === null) {
28
- return undefined;
29
- }
30
- if (!(metadataLike instanceof Map)) {
31
- throw Error("Expected metadata, if present, to be a Map<string, string>");
32
- }
33
- for (const item of metadataLike) {
34
- if (!(typeof item[0] === "string" || !(typeof item[1] === "string"))) {
35
- throw Error("Expected metadata, if present, to be a Map<string, string> but it had non-string keys or values");
36
- }
37
- }
38
- return metadataLike;
39
- }
40
- exports.sanitizeMetadata = sanitizeMetadata;
41
- function sanitizeInt(typeLike) {
42
- if (!("bitWidth" in typeLike) ||
43
- typeof typeLike.bitWidth !== "number" ||
44
- !("isSigned" in typeLike) ||
45
- typeof typeLike.isSigned !== "boolean") {
46
- throw Error("Expected an Int Type to have a `bitWidth` and `isSigned` property");
47
- }
48
- return new arrow_1.Int(typeLike.isSigned, typeLike.bitWidth);
49
- }
50
- exports.sanitizeInt = sanitizeInt;
51
- function sanitizeFloat(typeLike) {
52
- if (!("precision" in typeLike) || typeof typeLike.precision !== "number") {
53
- throw Error("Expected a Float Type to have a `precision` property");
54
- }
55
- return new arrow_1.Float(typeLike.precision);
56
- }
57
- exports.sanitizeFloat = sanitizeFloat;
58
- function sanitizeDecimal(typeLike) {
59
- if (!("scale" in typeLike) ||
60
- typeof typeLike.scale !== "number" ||
61
- !("precision" in typeLike) ||
62
- typeof typeLike.precision !== "number" ||
63
- !("bitWidth" in typeLike) ||
64
- typeof typeLike.bitWidth !== "number") {
65
- throw Error("Expected a Decimal Type to have `scale`, `precision`, and `bitWidth` properties");
66
- }
67
- return new arrow_1.Decimal(typeLike.scale, typeLike.precision, typeLike.bitWidth);
68
- }
69
- exports.sanitizeDecimal = sanitizeDecimal;
70
- function sanitizeDate(typeLike) {
71
- if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
72
- throw Error("Expected a Date type to have a `unit` property");
73
- }
74
- return new arrow_1.Date_(typeLike.unit);
75
- }
76
- exports.sanitizeDate = sanitizeDate;
77
- function sanitizeTime(typeLike) {
78
- if (!("unit" in typeLike) ||
79
- typeof typeLike.unit !== "number" ||
80
- !("bitWidth" in typeLike) ||
81
- typeof typeLike.bitWidth !== "number") {
82
- throw Error("Expected a Time type to have `unit` and `bitWidth` properties");
83
- }
84
- return new arrow_1.Time(typeLike.unit, typeLike.bitWidth);
85
- }
86
- exports.sanitizeTime = sanitizeTime;
87
- function sanitizeTimestamp(typeLike) {
88
- if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
89
- throw Error("Expected a Timestamp type to have a `unit` property");
90
- }
91
- let timezone = null;
92
- if ("timezone" in typeLike && typeof typeLike.timezone === "string") {
93
- timezone = typeLike.timezone;
94
- }
95
- return new arrow_1.Timestamp(typeLike.unit, timezone);
96
- }
97
- exports.sanitizeTimestamp = sanitizeTimestamp;
98
- function sanitizeTypedTimestamp(typeLike,
99
- // eslint-disable-next-line @typescript-eslint/naming-convention
100
- Datatype) {
101
- let timezone = null;
102
- if ("timezone" in typeLike && typeof typeLike.timezone === "string") {
103
- timezone = typeLike.timezone;
104
- }
105
- return new Datatype(timezone);
106
- }
107
- exports.sanitizeTypedTimestamp = sanitizeTypedTimestamp;
108
- function sanitizeInterval(typeLike) {
109
- if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
110
- throw Error("Expected an Interval type to have a `unit` property");
111
- }
112
- return new arrow_1.Interval(typeLike.unit);
113
- }
114
- exports.sanitizeInterval = sanitizeInterval;
115
- function sanitizeList(typeLike) {
116
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
117
- throw Error("Expected a List type to have an array-like `children` property");
118
- }
119
- if (typeLike.children.length !== 1) {
120
- throw Error("Expected a List type to have exactly one child");
121
- }
122
- return new arrow_1.List(sanitizeField(typeLike.children[0]));
123
- }
124
- exports.sanitizeList = sanitizeList;
125
- function sanitizeStruct(typeLike) {
126
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
127
- throw Error("Expected a Struct type to have an array-like `children` property");
128
- }
129
- return new arrow_1.Struct(typeLike.children.map((child) => sanitizeField(child)));
130
- }
131
- exports.sanitizeStruct = sanitizeStruct;
132
- function sanitizeUnion(typeLike) {
133
- if (!("typeIds" in typeLike) ||
134
- !("mode" in typeLike) ||
135
- typeof typeLike.mode !== "number") {
136
- throw Error("Expected a Union type to have `typeIds` and `mode` properties");
137
- }
138
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
139
- throw Error("Expected a Union type to have an array-like `children` property");
140
- }
141
- return new arrow_1.Union(typeLike.mode,
142
- // biome-ignore lint/suspicious/noExplicitAny: skip
143
- typeLike.typeIds, typeLike.children.map((child) => sanitizeField(child)));
144
- }
145
- exports.sanitizeUnion = sanitizeUnion;
146
- function sanitizeTypedUnion(typeLike,
147
- // eslint-disable-next-line @typescript-eslint/naming-convention
148
- UnionType) {
149
- if (!("typeIds" in typeLike)) {
150
- throw Error("Expected a DenseUnion/SparseUnion type to have a `typeIds` property");
151
- }
152
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
153
- throw Error("Expected a DenseUnion/SparseUnion type to have an array-like `children` property");
154
- }
155
- return new UnionType(typeLike.typeIds, typeLike.children.map((child) => sanitizeField(child)));
156
- }
157
- exports.sanitizeTypedUnion = sanitizeTypedUnion;
158
- function sanitizeFixedSizeBinary(typeLike) {
159
- if (!("byteWidth" in typeLike) || typeof typeLike.byteWidth !== "number") {
160
- throw Error("Expected a FixedSizeBinary type to have a `byteWidth` property");
161
- }
162
- return new arrow_1.FixedSizeBinary(typeLike.byteWidth);
163
- }
164
- exports.sanitizeFixedSizeBinary = sanitizeFixedSizeBinary;
165
- function sanitizeFixedSizeList(typeLike) {
166
- if (!("listSize" in typeLike) || typeof typeLike.listSize !== "number") {
167
- throw Error("Expected a FixedSizeList type to have a `listSize` property");
168
- }
169
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
170
- throw Error("Expected a FixedSizeList type to have an array-like `children` property");
171
- }
172
- if (typeLike.children.length !== 1) {
173
- throw Error("Expected a FixedSizeList type to have exactly one child");
174
- }
175
- return new arrow_1.FixedSizeList(typeLike.listSize, sanitizeField(typeLike.children[0]));
176
- }
177
- exports.sanitizeFixedSizeList = sanitizeFixedSizeList;
178
- function sanitizeMap(typeLike) {
179
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
180
- throw Error("Expected a Map type to have an array-like `children` property");
181
- }
182
- if (!("keysSorted" in typeLike) || typeof typeLike.keysSorted !== "boolean") {
183
- throw Error("Expected a Map type to have a `keysSorted` property");
184
- }
185
- return new arrow_1.Map_(
186
- // biome-ignore lint/suspicious/noExplicitAny: skip
187
- typeLike.children.map((field) => sanitizeField(field)), typeLike.keysSorted);
188
- }
189
- exports.sanitizeMap = sanitizeMap;
190
- function sanitizeDuration(typeLike) {
191
- if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
192
- throw Error("Expected a Duration type to have a `unit` property");
193
- }
194
- return new arrow_1.Duration(typeLike.unit);
195
- }
196
- exports.sanitizeDuration = sanitizeDuration;
197
- function sanitizeDictionary(typeLike) {
198
- if (!("id" in typeLike) || typeof typeLike.id !== "number") {
199
- throw Error("Expected a Dictionary type to have an `id` property");
200
- }
201
- if (!("indices" in typeLike) || typeof typeLike.indices !== "object") {
202
- throw Error("Expected a Dictionary type to have an `indices` property");
203
- }
204
- if (!("dictionary" in typeLike) || typeof typeLike.dictionary !== "object") {
205
- throw Error("Expected a Dictionary type to have an `dictionary` property");
206
- }
207
- if (!("isOrdered" in typeLike) || typeof typeLike.isOrdered !== "boolean") {
208
- throw Error("Expected a Dictionary type to have an `isOrdered` property");
209
- }
210
- return new arrow_1.Dictionary(sanitizeType(typeLike.dictionary), sanitizeType(typeLike.indices), typeLike.id, typeLike.isOrdered);
211
- }
212
- exports.sanitizeDictionary = sanitizeDictionary;
213
- // biome-ignore lint/suspicious/noExplicitAny: skip
214
- function sanitizeType(typeLike) {
215
- if (typeof typeLike !== "object" || typeLike === null) {
216
- throw Error("Expected a Type but object was null/undefined");
217
- }
218
- if (!("typeId" in typeLike) || !(typeof typeLike.typeId !== "function")) {
219
- throw Error("Expected a Type to have a typeId function");
220
- }
221
- let typeId;
222
- if (typeof typeLike.typeId === "function") {
223
- typeId = typeLike.typeId();
224
- }
225
- else if (typeof typeLike.typeId === "number") {
226
- typeId = typeLike.typeId;
227
- }
228
- else {
229
- throw Error("Type's typeId property was not a function or number");
230
- }
231
- switch (typeId) {
232
- case arrow_1.Type.NONE:
233
- throw Error("Received a Type with a typeId of NONE");
234
- case arrow_1.Type.Null:
235
- return new arrow_1.Null();
236
- case arrow_1.Type.Int:
237
- return sanitizeInt(typeLike);
238
- case arrow_1.Type.Float:
239
- return sanitizeFloat(typeLike);
240
- case arrow_1.Type.Binary:
241
- return new arrow_1.Binary();
242
- case arrow_1.Type.Utf8:
243
- return new arrow_1.Utf8();
244
- case arrow_1.Type.Bool:
245
- return new arrow_1.Bool();
246
- case arrow_1.Type.Decimal:
247
- return sanitizeDecimal(typeLike);
248
- case arrow_1.Type.Date:
249
- return sanitizeDate(typeLike);
250
- case arrow_1.Type.Time:
251
- return sanitizeTime(typeLike);
252
- case arrow_1.Type.Timestamp:
253
- return sanitizeTimestamp(typeLike);
254
- case arrow_1.Type.Interval:
255
- return sanitizeInterval(typeLike);
256
- case arrow_1.Type.List:
257
- return sanitizeList(typeLike);
258
- case arrow_1.Type.Struct:
259
- return sanitizeStruct(typeLike);
260
- case arrow_1.Type.Union:
261
- return sanitizeUnion(typeLike);
262
- case arrow_1.Type.FixedSizeBinary:
263
- return sanitizeFixedSizeBinary(typeLike);
264
- case arrow_1.Type.FixedSizeList:
265
- return sanitizeFixedSizeList(typeLike);
266
- case arrow_1.Type.Map:
267
- return sanitizeMap(typeLike);
268
- case arrow_1.Type.Duration:
269
- return sanitizeDuration(typeLike);
270
- case arrow_1.Type.Dictionary:
271
- return sanitizeDictionary(typeLike);
272
- case arrow_1.Type.Int8:
273
- return new arrow_1.Int8();
274
- case arrow_1.Type.Int16:
275
- return new arrow_1.Int16();
276
- case arrow_1.Type.Int32:
277
- return new arrow_1.Int32();
278
- case arrow_1.Type.Int64:
279
- return new arrow_1.Int64();
280
- case arrow_1.Type.Uint8:
281
- return new arrow_1.Uint8();
282
- case arrow_1.Type.Uint16:
283
- return new arrow_1.Uint16();
284
- case arrow_1.Type.Uint32:
285
- return new arrow_1.Uint32();
286
- case arrow_1.Type.Uint64:
287
- return new arrow_1.Uint64();
288
- case arrow_1.Type.Float16:
289
- return new arrow_1.Float16();
290
- case arrow_1.Type.Float32:
291
- return new arrow_1.Float32();
292
- case arrow_1.Type.Float64:
293
- return new arrow_1.Float64();
294
- case arrow_1.Type.DateMillisecond:
295
- return new arrow_1.DateMillisecond();
296
- case arrow_1.Type.DateDay:
297
- return new arrow_1.DateDay();
298
- case arrow_1.Type.TimeNanosecond:
299
- return new arrow_1.TimeNanosecond();
300
- case arrow_1.Type.TimeMicrosecond:
301
- return new arrow_1.TimeMicrosecond();
302
- case arrow_1.Type.TimeMillisecond:
303
- return new arrow_1.TimeMillisecond();
304
- case arrow_1.Type.TimeSecond:
305
- return new arrow_1.TimeSecond();
306
- case arrow_1.Type.TimestampNanosecond:
307
- return sanitizeTypedTimestamp(typeLike, arrow_1.TimestampNanosecond);
308
- case arrow_1.Type.TimestampMicrosecond:
309
- return sanitizeTypedTimestamp(typeLike, arrow_1.TimestampMicrosecond);
310
- case arrow_1.Type.TimestampMillisecond:
311
- return sanitizeTypedTimestamp(typeLike, arrow_1.TimestampMillisecond);
312
- case arrow_1.Type.TimestampSecond:
313
- return sanitizeTypedTimestamp(typeLike, arrow_1.TimestampSecond);
314
- case arrow_1.Type.DenseUnion:
315
- return sanitizeTypedUnion(typeLike, arrow_1.DenseUnion);
316
- case arrow_1.Type.SparseUnion:
317
- return sanitizeTypedUnion(typeLike, arrow_1.SparseUnion);
318
- case arrow_1.Type.IntervalDayTime:
319
- return new arrow_1.IntervalDayTime();
320
- case arrow_1.Type.IntervalYearMonth:
321
- return new arrow_1.IntervalYearMonth();
322
- case arrow_1.Type.DurationNanosecond:
323
- return new arrow_1.DurationNanosecond();
324
- case arrow_1.Type.DurationMicrosecond:
325
- return new arrow_1.DurationMicrosecond();
326
- case arrow_1.Type.DurationMillisecond:
327
- return new arrow_1.DurationMillisecond();
328
- case arrow_1.Type.DurationSecond:
329
- return new arrow_1.DurationSecond();
330
- default:
331
- throw new Error("Unrecoginized type id in schema: " + typeId);
332
- }
333
- }
334
- exports.sanitizeType = sanitizeType;
335
- function sanitizeField(fieldLike) {
336
- if (fieldLike instanceof arrow_1.Field) {
337
- return fieldLike;
338
- }
339
- if (typeof fieldLike !== "object" || fieldLike === null) {
340
- throw Error("Expected a Field but object was null/undefined");
341
- }
342
- if (!("type" in fieldLike) ||
343
- !("name" in fieldLike) ||
344
- !("nullable" in fieldLike)) {
345
- throw Error("The field passed in is missing a `type`/`name`/`nullable` property");
346
- }
347
- const type = sanitizeType(fieldLike.type);
348
- const name = fieldLike.name;
349
- if (!(typeof name === "string")) {
350
- throw Error("The field passed in had a non-string `name` property");
351
- }
352
- const nullable = fieldLike.nullable;
353
- if (!(typeof nullable === "boolean")) {
354
- throw Error("The field passed in had a non-boolean `nullable` property");
355
- }
356
- let metadata;
357
- if ("metadata" in fieldLike) {
358
- metadata = sanitizeMetadata(fieldLike.metadata);
359
- }
360
- return new arrow_1.Field(name, type, nullable, metadata);
361
- }
362
- exports.sanitizeField = sanitizeField;
363
- /**
364
- * Convert something schemaLike into a Schema instance
365
- *
366
- * This method is often needed even when the caller is using a Schema
367
- * instance because they might be using a different instance of apache-arrow
368
- * than lancedb is using.
369
- */
370
- function sanitizeSchema(schemaLike) {
371
- if (schemaLike instanceof arrow_1.Schema) {
372
- return schemaLike;
373
- }
374
- if (typeof schemaLike !== "object" || schemaLike === null) {
375
- throw Error("Expected a Schema but object was null/undefined");
376
- }
377
- if (!("fields" in schemaLike)) {
378
- throw Error("The schema passed in does not appear to be a schema (no 'fields' property)");
379
- }
380
- let metadata;
381
- if ("metadata" in schemaLike) {
382
- metadata = sanitizeMetadata(schemaLike.metadata);
383
- }
384
- if (!Array.isArray(schemaLike.fields)) {
385
- throw Error("The schema passed in had a 'fields' property but it was not an array");
386
- }
387
- const sanitizedFields = schemaLike.fields.map((field) => sanitizeField(field));
388
- return new arrow_1.Schema(sanitizedFields, metadata);
389
- }
390
- exports.sanitizeSchema = sanitizeSchema;
391
- function sanitizeTable(tableLike) {
392
- if (tableLike instanceof arrow_1.Table) {
393
- return tableLike;
394
- }
395
- if (typeof tableLike !== "object" || tableLike === null) {
396
- throw Error("Expected a Table but object was null/undefined");
397
- }
398
- if (!("schema" in tableLike)) {
399
- throw Error("The table passed in does not appear to be a table (no 'schema' property)");
400
- }
401
- if (!("batches" in tableLike)) {
402
- throw Error("The table passed in does not appear to be a table (no 'columns' property)");
403
- }
404
- const schema = sanitizeSchema(tableLike.schema);
405
- const batches = tableLike.batches.map(sanitizeRecordBatch);
406
- return new arrow_1.Table(schema, batches);
407
- }
408
- exports.sanitizeTable = sanitizeTable;
409
- function sanitizeRecordBatch(batchLike) {
410
- if (batchLike instanceof arrow_1.RecordBatch) {
411
- return batchLike;
412
- }
413
- if (typeof batchLike !== "object" || batchLike === null) {
414
- throw Error("Expected a RecordBatch but object was null/undefined");
415
- }
416
- if (!("schema" in batchLike)) {
417
- throw Error("The record batch passed in does not appear to be a record batch (no 'schema' property)");
418
- }
419
- if (!("data" in batchLike)) {
420
- throw Error("The record batch passed in does not appear to be a record batch (no 'data' property)");
421
- }
422
- const schema = sanitizeSchema(batchLike.schema);
423
- const data = sanitizeData(batchLike.data);
424
- return new arrow_1.RecordBatch(schema, data);
425
- }
426
- function sanitizeData(dataLike) {
427
- if (dataLike instanceof apache_arrow_1.Data) {
428
- return dataLike;
429
- }
430
- return new apache_arrow_1.Data(dataLike.type, dataLike.offset, dataLike.length, dataLike.nullCount, {
431
- [apache_arrow_1.BufferType.OFFSET]: dataLike.valueOffsets,
432
- [apache_arrow_1.BufferType.DATA]: dataLike.values,
433
- [apache_arrow_1.BufferType.VALIDITY]: dataLike.nullBitmap,
434
- [apache_arrow_1.BufferType.TYPE]: dataLike.typeIds,
435
- });
436
- }