Skip to content

Commit

Permalink
chore(zql): update all createSchema references
Browse files Browse the repository at this point in the history
  • Loading branch information
tantaman committed Jan 21, 2025
1 parent c98fd29 commit 5c019ac
Show file tree
Hide file tree
Showing 25 changed files with 442 additions and 434 deletions.
20 changes: 5 additions & 15 deletions apps/zbugs/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,16 @@ type AuthData = {
role: 'crew' | 'user';
};

export const schema = createSchema(
5,
{
user,
issue,
comment,
label,
issueLabel,
viewState,
emoji,
userPref,
},
{
export const schema = createSchema(5, {
tables: [user, issue, comment, label, issueLabel, viewState, emoji, userPref],
relationships: [
userRelationships,
issueRelationships,
commentRelationships,
issueLabelRelationships,
emojiRelationships,
},
);
],
});

export type Schema = typeof schema;
type TableName = keyof Schema['tables'];
Expand Down
18 changes: 4 additions & 14 deletions packages/zero-cache/bench/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,10 @@ const commentRelationships = relationships(comment, connect => ({
}),
}));

export const schema = createSchema(
1,
{
member,
issue,
comment,
label,
issueLabel,
},
{
issueRelationships,
commentRelationships,
},
);
export const schema = createSchema(1, {
tables: [member, issue, comment, label, issueLabel],
relationships: [issueRelationships, commentRelationships],
});

type AppSchema = typeof schema;
export type {AppSchema as Schema};
13 changes: 6 additions & 7 deletions packages/zero-cache/src/auth/read-authorizer.query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ type AuthData = {
};
};

const schema = createSchema(
1,
{
const schema = createSchema(1, {
tables: [
user,
issue,
comment,
Expand All @@ -277,17 +276,17 @@ const schema = createSchema(
viewState,
project,
projectMember,
},
{
],
relationships: [
userRelationships,
issueRelationships,
commentRelationships,
issueLabelRelationships,
viewStateRelationships,
projectRelationships,
projectMemberRelationships,
},
);
],
});

type Schema = typeof schema;

Expand Down
22 changes: 8 additions & 14 deletions packages/zero-cache/src/auth/read-authorizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,14 @@ const adminReadableRelationships = relationships(adminReadable, connect => ({
}),
}));

const schema = createSchema(
1,
{
unreadable,
readable,
adminReadable,
readableThruUnreadable,
},
{
readableThruUnreadable: readableThruUnreadableRelationships,
readable: readableRelationships,
adminReadable: adminReadableRelationships,
},
);
const schema = createSchema(1, {
tables: [unreadable, readable, adminReadable, readableThruUnreadable],
relationships: [
readableThruUnreadableRelationships,
readableRelationships,
adminReadableRelationships,
],
});

type Schema = typeof schema;

Expand Down
14 changes: 8 additions & 6 deletions packages/zero-cache/src/auth/write-authorizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ const allowIfAIsSubject = [
] satisfies Rule;

const schema = createSchema(1, {
foo: table('foo')
.columns({
id: string(),
a: string(),
})
.primaryKey('id'),
tables: [
table('foo')
.columns({
id: string(),
a: string(),
})
.primaryKey('id'),
],
});

let replica: Database;
Expand Down
126 changes: 64 additions & 62 deletions packages/zero-cache/src/services/mutagen/mutagen.authz.pg-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,68 +121,70 @@ function createReplicaTables(db: Database) {
}

const schema = createSchema(TEST_SCHEMA_VERSION, {
user: table('user')
.columns({
id: string(),
role: string(),
})
.primaryKey('id'),

roCell: table('roCell')
.columns({
id: string(),
a: string(),
b: string(),
})
.primaryKey('id'),

roRow: table('roRow')
.columns({
id: string(),
a: string(),
b: string(),
})
.primaryKey('id'),

adminOnlyCell: table('adminOnlyCell')
.columns({
id: string(),
a: string(),
adminLocked: boolean(),
})
.primaryKey('id'),

adminOnlyRow: table('adminOnlyRow')
.columns({
id: string(),
a: string(),
adminLocked: boolean(),
})
.primaryKey('id'),

loggedInRow: table('loggedInRow')
.columns({
id: string(),
a: string(),
})
.primaryKey('id'),

userMatch: table('userMatch')
.columns({
id: string(),
a: string(),
})
.primaryKey('id'),

dataTypeTest: table('dataTypeTest')
.columns({
id: string(),
j: json().optional(),
b: boolean().optional(),
r: number().optional(),
i: number().optional(),
})
.primaryKey('id'),
tables: [
table('user')
.columns({
id: string(),
role: string(),
})
.primaryKey('id'),

table('roCell')
.columns({
id: string(),
a: string(),
b: string(),
})
.primaryKey('id'),

table('roRow')
.columns({
id: string(),
a: string(),
b: string(),
})
.primaryKey('id'),

table('adminOnlyCell')
.columns({
id: string(),
a: string(),
adminLocked: boolean(),
})
.primaryKey('id'),

table('adminOnlyRow')
.columns({
id: string(),
a: string(),
adminLocked: boolean(),
})
.primaryKey('id'),

table('loggedInRow')
.columns({
id: string(),
a: string(),
})
.primaryKey('id'),

table('userMatch')
.columns({
id: string(),
a: string(),
})
.primaryKey('id'),

table('dataTypeTest')
.columns({
id: string(),
j: json().optional(),
b: boolean().optional(),
r: number().optional(),
i: number().optional(),
})
.primaryKey('id'),
],
});

type Schema = typeof schema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,18 @@ const comments = table('comments')
})
.primaryKey('id');

const schema = createSchema(
1,
{
issues,
comments,
},
{
commentRelationships: relationships(comments, connect => ({
const schema = createSchema(1, {
tables: [issues, comments],
relationships: [
relationships(comments, connect => ({
issue: connect.many({
sourceField: ['issueID'],
destField: ['id'],
destSchema: issues,
}),
})),
},
);
],
});
type Schema = typeof schema;

type AuthData = {
Expand Down
66 changes: 36 additions & 30 deletions packages/zero-client/src/client/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ const testBatchViewUpdates = (applyViewUpdates: () => void) =>

test('getSource', () => {
const schema = createSchema(1, {
users: table('users')
.columns({
id: string(),
name: string(),
})
.primaryKey('id'),
userStates: table('userStates')
.columns({
userID: string(),
stateCode: string(),
})
.primaryKey('userID', 'stateCode'),
tables: [
table('users')
.columns({
id: string(),
name: string(),
})
.primaryKey('id'),
table('userStates')
.columns({
userID: string(),
stateCode: string(),
})
.primaryKey('userID', 'stateCode'),
],
});

const context = new ZeroContext(
Expand Down Expand Up @@ -88,12 +90,14 @@ test('getSource', () => {
`);
});
const schema = createSchema(1, {
t1: table('t1')
.columns({
id: string(),
name: string(),
})
.primaryKey('id'),
tables: [
table('t1')
.columns({
id: string(),
name: string(),
})
.primaryKey('id'),
],
});

test('processChanges', () => {
Expand Down Expand Up @@ -196,18 +200,20 @@ test('processChanges wraps source updates with batchViewUpdates', () => {

test('transactions', () => {
const schema = createSchema(1, {
server: table('server')
.columns({
id: string(),
})
.primaryKey('id'),
flair: table('flair')
.columns({
id: string(),
serverID: string(),
description: string(),
})
.primaryKey('id'),
tables: [
table('server')
.columns({
id: string(),
})
.primaryKey('id'),
table('flair')
.columns({
id: string(),
serverID: string(),
description: string(),
})
.primaryKey('id'),
],
});

const context = new ZeroContext(
Expand Down
Loading

0 comments on commit 5c019ac

Please sign in to comment.