Skip to content

Commit

Permalink
Merge branch 'main' into fp/minimal-fts
Browse files Browse the repository at this point in the history
* main:
  Pushing update to the package-lock.json
  Binding resolution refactored (#5802)
  Update install-test-react-native.yml (#5808)
  Add more testing of IN operator (#5809)
  • Loading branch information
papafe committed May 16, 2023
2 parents d1c3bb9 + 412d5a6 commit b2fad35
Show file tree
Hide file tree
Showing 24 changed files with 106 additions and 93 deletions.
1 change: 1 addition & 0 deletions .github/workflows/install-test-react-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ jobs:
- uses: ruby/setup-ruby@v1
if: ${{ matrix.platform == 'ios' }}
with:
ruby-version: '3.0'
bundler-cache: true
working-directory: install-tests/react-native/app

Expand Down
6 changes: 6 additions & 0 deletions integration-tests/tests/src/tests/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,12 @@ describe("Queries", () => {

const dennis = persons.filtered("name in {'Dennis'}");
expect(dennis.length).equal(0);

const bobs = persons.filtered("name in $0", ["Bob"]);
expect(bobs.length).equal(1);

const many = persons.filtered("name in $0", ["Alice", "Dennis", "Bob"]);
expect(many.length).equal(2);
});

it("array of primitive types", () => {
Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/realm/.mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"loader": "tsx",
"enable-source-maps": true,
"no-warnings": true,
"require": "src/node/index.ts",
"require": "src/platform/node/index.ts",
"spec": "src/tests/*.test.ts"
}
4 changes: 2 additions & 2 deletions packages/realm/bindgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ bindgen(
)

set(GENERATED_JS_FILES
${TYPESCRIPT_OUTPUT_DIR}/native.mjs
${TYPESCRIPT_OUTPUT_DIR}/native-rn.mjs
${TYPESCRIPT_OUTPUT_DIR}/native-node.mjs
${TYPESCRIPT_OUTPUT_DIR}/native-react-native.mjs
)
bindgen(
TEMPLATE ${SDK_DIR}/bindgen/src/templates/node-wrapper.ts
Expand Down
3 changes: 3 additions & 0 deletions packages/realm/bindgen/src/eslint-formatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { createCommandFormatter } from "@realm/bindgen/formatter";

export const eslint = createCommandFormatter("eslint", ["npx", "eslint", "--fix", "--format=stylish"]);
3 changes: 2 additions & 1 deletion packages/realm/bindgen/src/templates/jsi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from "@realm/bindgen/bound-model";

import { doJsPasses } from "../js-passes";
import { clangFormat } from "@realm/bindgen/formatter";

// Code assumes this is a unique name that is always in scope to refer to the jsi::Runtime.
// Callbacks need to ensure this is in scope. Functions taking Runtime arguments must use this name.
Expand Down Expand Up @@ -1040,7 +1041,7 @@ class JsiCppDecls extends CppDecls {
}

export function generate({ spec, file: makeFile }: TemplateContext): void {
const out = makeFile("jsi_init.cpp", "clang-format");
const out = makeFile("jsi_init.cpp", clangFormat);

// HEADER
out(`// This file is generated: Update the spec instead of editing this file directly`);
Expand Down
11 changes: 6 additions & 5 deletions packages/realm/bindgen/src/templates/node-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import { bindModel, Property } from "@realm/bindgen/bound-model";
import { TemplateContext } from "@realm/bindgen/context";

import { doJsPasses } from "../js-passes";
import { eslint } from "../eslint-formatter";

export function generate({ spec: rawSpec, file }: TemplateContext): void {
const spec = doJsPasses(bindModel(rawSpec));
const reactLines = [];
const nodeLines = [];
function both(content: string) {
reactLines.push(content);
nodeLines.push(content);
function both(...content: string[]) {
reactLines.push(...content);
nodeLines.push(...content);
}

both("// This file is generated: Update the spec instead of editing this file directly");
Expand Down Expand Up @@ -204,6 +205,6 @@ export function generate({ spec: rawSpec, file }: TemplateContext): void {

both(`nativeModule.injectInjectables({ ${injectables} });`);

file("native.mjs", "eslint")(nodeLines.join("\n"));
file("native-rn.mjs", "eslint")(reactLines.join("\n"));
file("native-node.mjs", eslint)(nodeLines.join("\n"));
file("native-react-native.mjs", eslint)(reactLines.join("\n"));
}
3 changes: 2 additions & 1 deletion packages/realm/bindgen/src/templates/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
Pointer,
Template,
} from "@realm/bindgen/bound-model";
import { clangFormat } from "@realm/bindgen/formatter";

import { doJsPasses } from "../js-passes";

Expand Down Expand Up @@ -896,7 +897,7 @@ class NodeCppDecls extends CppDecls {
}

export function generate({ spec, file: makeFile }: TemplateContext): void {
const out = makeFile("node_init.cpp", "clang-format");
const out = makeFile("node_init.cpp", clangFormat);

// HEADER
out(`// This file is generated: Update the spec instead of editing this file directly`);
Expand Down
33 changes: 12 additions & 21 deletions packages/realm/bindgen/src/templates/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,13 @@
//
////////////////////////////////////////////////////////////////////////////

import { strict as assert } from "node:assert";

import { TemplateContext } from "@realm/bindgen/context";
import { Arg, BoundSpec, NamedType, Property, Type, bindModel } from "@realm/bindgen/bound-model";
import { strict as assert } from "assert";

import { doJsPasses } from "../js-passes";

import { addFormatter } from "@realm/bindgen/formatter";

// Ideally, this would be codified in a tsconfig.json, but tsc doesn't support
// configs mixed with filenames when invoked via the CLI.
addFormatter("typescript-checker", [
"npx",
"tsc",
"--noEmit",
"--noResolve",
"--lib",
"es2022",
"--types",
"buffer,bson",
]);
import { eslint } from "../eslint-formatter";

const PRIMITIVES_MAPPING: Record<string, string> = {
void: "void",
Expand Down Expand Up @@ -162,7 +149,7 @@ export function generate({ spec: rawSpec, file }: TemplateContext): void {

const spec = doJsPasses(bindModel(rawSpec));

const coreOut = file("core.ts", "eslint", "typescript-checker");
const coreOut = file("core.ts", eslint);
coreOut("// This file is generated: Update the spec instead of editing this file directly");

coreOut("// Enums");
Expand All @@ -180,12 +167,14 @@ export function generate({ spec: rawSpec, file }: TemplateContext): void {
}
`);

const out = file("native.d.mts", "eslint", "typescript-checker");
const out = file("native.d.mts", eslint);
out("// This file is generated: Update the spec instead of editing this file directly");

out("declare module 'realm/binding' {");

out('import { ObjectId, UUID, Decimal128 } from "bson";');
out("import { Float, ", spec.enums.map((e) => e.name).join(", "), '} from "./core";');
out('export * from "./core";');
out("import { Float, ", spec.enums.map((e) => e.name).join(", "), '} from "realm/binding/core";');
out('export * from "realm/binding/core";');

out("// Utilities");
out("export type AppError = Error & {code: number};");
Expand Down Expand Up @@ -216,7 +205,7 @@ export function generate({ spec: rawSpec, file }: TemplateContext): void {

out("// Opaque types (including Key types)");
for (const { jsName } of (spec.opaqueTypes as NamedType[]).concat(spec.keyTypes)) {
out.lines("/** Using an empty enum to express a nominal type */", `export declare enum ${jsName} {}`);
out.lines("/** Using an empty enum to express a nominal type */", `export enum ${jsName} {}`);
}

out("// Records");
Expand Down Expand Up @@ -278,4 +267,6 @@ export function generate({ spec: rawSpec, file }: TemplateContext): void {
}
out(`}`);
}

out("} // end of module declaration");
}
4 changes: 2 additions & 2 deletions packages/realm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@
"bindgen/src/templates/node-wrapper.ts"
],
"output": [
"generated/ts/native.mjs",
"generated/ts/native-rn.mjs"
"generated/ts/native-node.mjs",
"generated/ts/native-react-native.mjs"
]
},
"bindgen:generate:spec-schema": {
Expand Down
15 changes: 4 additions & 11 deletions packages/realm/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (ENABLE_TEST_COVERAGE_INSTRUMENTATION) {

export default [
{
input: "src/node/index.ts",
input: "src/platform/node/index.ts",
output: [
{
file: mainExport.node,
Expand Down Expand Up @@ -72,15 +72,15 @@ export default [
}),
json(),
typescript({
tsconfig: "src/node/tsconfig.json",
tsconfig: "src/platform/node/tsconfig.json",
noEmitOnError: true,
outputToFilesystem: true,
}),
],
external: ["bson", "debug", "node-fetch", "node:module", "node:fs", "node:path"],
},
{
input: "src/react-native/index.ts",
input: "src/platform/react-native/index.ts",
output: {
file: mainExport["react-native"],
format: "es",
Expand All @@ -94,16 +94,9 @@ export default [
}),
// We need to use `commonjs` because of "path-browserify"
commonjs(),
replace({
preventAssignment: true,
delimiters: ["", ""],
values: {
'"../generated/ts/native.mjs"': '"../generated/ts/native-rn.mjs"',
},
}),
json(),
typescript({
tsconfig: "src/react-native/tsconfig.json",
tsconfig: "src/platform/react-native/tsconfig.json",
noEmitOnError: true,
outputToFilesystem: true,
}),
Expand Down
6 changes: 3 additions & 3 deletions packages/realm/src/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
//
////////////////////////////////////////////////////////////////////////////

import { IndexSet, Int64, ObjKey, Timestamp } from "../generated/ts/native.mjs";
import { IndexSet, Int64, ObjKey, Timestamp } from "realm/binding";

/** @internal */
export * from "../generated/ts/native.mjs"; // core types are transitively exported.
export * from "realm/binding";

/** @internal */
declare module "../generated/ts/native.mjs" {
declare module "realm/binding" {
interface IndexSet {
asIndexes(): Iterator<number>;
}
Expand Down
14 changes: 0 additions & 14 deletions packages/realm/src/node/tsconfig.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import os from "node:os";

import { version } from "realm/package.json";

import { inject } from "../platform/device-info";
import { inject } from "../device-info";

inject({
create() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import { existsSync, mkdirSync, readdirSync, rmSync, unlinkSync } from "node:fs";
import { dirname, isAbsolute, join } from "node:path";

import { inject } from "../platform/file-system";
import { extendDebug } from "../debug";
import { inject } from "../file-system";
import { extendDebug } from "../../debug";

const debug = extendDebug("fs");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
import "./fs";
import "./device-info";

export * from "../index";
import { Realm } from "../index";
export * from "../../index";
import { Realm } from "../../index";
export default Realm;
18 changes: 18 additions & 0 deletions packages/realm/src/platform/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"types": ["node"],
"noResolve": false,
"incremental": true,
"resolveJsonModule": true,
"paths": {
"realm/binding": ["./generated/ts/native-node.mjs"],
"realm/binding/core": ["./generated/ts/core.ts"]
}
},
"exclude": [
"../../tests/",
"../react-native/",
"../../../type-tests/"
],
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { Platform } from "react-native";

import { version } from "realm/package.json";

import { inject } from "../platform/device-info";
import { JsPlatformHelpers } from "../binding";
import { inject } from "../device-info";
import { JsPlatformHelpers } from "../../binding";

function getDeviceName() {
if (Platform.OS === "ios") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
////////////////////////////////////////////////////////////////////////////
import { isAbsolute, join } from "path-browserify";

import { inject } from "../platform/file-system";
import { extendDebug } from "../debug";
import { Helpers, JsPlatformHelpers } from "../binding";
import { inject } from "../file-system";
import { extendDebug } from "../../debug";
import { Helpers, JsPlatformHelpers } from "../../binding";

const debug = extendDebug("fs");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
import "./fs";
import "./device-info";

export * from "../index";
import { Realm } from "../index";
export * from "../../index";
import { Realm } from "../../index";
export default Realm;
21 changes: 21 additions & 0 deletions packages/realm/src/platform/react-native/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"noResolve": false,
"incremental": true,
"resolveJsonModule": true,
"types": [
"react-native",
"path-browserify"
],
"paths": {
"realm/binding": ["./generated/ts/native-react-native.mjs"],
"realm/binding/core": ["./generated/ts/core.ts"]
}
},
"exclude": [
"../../tests/",
"../node/",
"../../../type-tests/"
],
}
Loading

0 comments on commit b2fad35

Please sign in to comment.