@saltcorn/builder 0.9.4-beta.0 → 0.9.4-beta.10

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.
@@ -1,163 +0,0 @@
1
- import { readFileSync } from "fs";
2
- import { join } from "path";
3
-
4
- export const fixturesData = () => {
5
- const { tables, views } = JSON.parse(
6
- readFileSync(join(__dirname, "schema_data.json"))
7
- );
8
- return { tables, views };
9
- };
10
-
11
- let nextFieldId = 3000;
12
-
13
- export const withAnotherUserField = () => {
14
- const { tables, views } = JSON.parse(JSON.stringify(fixturesData()));
15
- const uiit = tables.find(({ name }) => name === "user_interested_in_topic");
16
- uiit.foreign_keys.push({
17
- name: "another_user",
18
- id: nextFieldId++,
19
- table_id: uiit.id,
20
- reftable_name: "users",
21
- is_unique: false,
22
- });
23
- return { tables, views };
24
- };
25
-
26
- export const withSecondTopicField = () => {
27
- const { tables, views } = JSON.parse(JSON.stringify(withAnotherUserField()));
28
- const bit = tables.find(({ name }) => name === "blog_in_topic");
29
- bit.foreign_keys.push({
30
- name: "second_topic",
31
- id: nextFieldId++,
32
- table_id: bit.id,
33
- reftable_name: "topics",
34
- is_unique: false,
35
- });
36
- return { tables, views };
37
- };
38
-
39
- export const withMultipleInbounds = () => {
40
- const { tables, views } = JSON.parse(JSON.stringify(withSecondTopicField()));
41
- const nextTableId = tables.length + 1;
42
- tables.push({
43
- name: "second_inbound",
44
- id: nextTableId,
45
- foreign_keys: [
46
- {
47
- name: "topic",
48
- id: nextFieldId++,
49
- table_id: nextTableId,
50
- reftable_name: "topics",
51
- is_unique: false,
52
- },
53
- {
54
- name: "user",
55
- id: nextFieldId++,
56
- table_id: nextTableId,
57
- reftable_name: "users",
58
- is_unique: false,
59
- },
60
- ],
61
- });
62
- return { tables, views };
63
- };
64
-
65
- export const withKeyFromLayerTwo = () => {
66
- const { tables, views } = JSON.parse(JSON.stringify(withMultipleInbounds()));
67
- const inboundInbound = tables.find(({ name }) => name === "inbound_inbound");
68
- inboundInbound.foreign_keys.push({
69
- name: "post_from_layer_two",
70
- id: nextFieldId++,
71
- table_id: inboundInbound.id,
72
- reftable_name: "blog_posts",
73
- is_unique: false,
74
- });
75
- return { tables, views };
76
- };
77
-
78
- export const withKeyFromLayerThree = () => {
79
- const { tables, views } = JSON.parse(JSON.stringify(withKeyFromLayerTwo()));
80
- const nextTableId = tables.length + 1;
81
- tables.push({
82
- name: "inbound_level_three",
83
- id: nextTableId,
84
- foreign_keys: [
85
- {
86
- name: "inbound_level_two",
87
- id: nextFieldId++,
88
- table_id: nextTableId,
89
- reftable_name: "inbound_inbound",
90
- is_unique: false,
91
- },
92
- {
93
- name: "topic",
94
- id: nextFieldId++,
95
- table_id: nextTableId,
96
- reftable_name: "topics",
97
- is_unique: false,
98
- },
99
- ],
100
- });
101
- return { tables, views };
102
- };
103
-
104
- export const withSimplePostTopicrelation = () => {
105
- const { tables, views } = JSON.parse(JSON.stringify(fixturesData()));
106
- const simpleTopicsId = tables.length + 1;
107
- const simplePostsId = simpleTopicsId + 1;
108
- const simplePostInboundId = simplePostsId + 1;
109
- tables.push({
110
- name: "simple_posts",
111
- id: simplePostsId,
112
- foreign_keys: [
113
- {
114
- name: "topic",
115
- table_id: simplePostsId,
116
- id: nextFieldId++,
117
- reftable_name: "simple_topics",
118
- is_unique: false,
119
- },
120
- ],
121
- });
122
- tables.push({
123
- name: "simple_topics",
124
- id: simpleTopicsId,
125
- foreign_keys: [],
126
- });
127
- tables.push({
128
- name: "simple_post_inbound",
129
- id: simplePostInboundId,
130
- foreign_keys: [
131
- {
132
- name: "post",
133
- table_id: simplePostInboundId,
134
- id: nextFieldId++,
135
- reftable_name: "simple_posts",
136
- is_unique: false,
137
- },
138
- {
139
- name: "topic",
140
- table_id: simplePostInboundId,
141
- id: nextFieldId++,
142
- reftable_name: "simple_topics",
143
- is_unique: false,
144
- },
145
- ],
146
- });
147
- const users = tables.find(({ name }) => name === "users");
148
- users.foreign_keys.push({
149
- name: "favsimpletopic",
150
- table_id: users.id,
151
- id: nextFieldId++,
152
- reftable_name: "simple_topics",
153
- is_unique: false,
154
- });
155
-
156
- views.push({
157
- name: "simple_posts_list",
158
- table_id: simplePostsId,
159
- display_type: "NO_ROW_LIMIT",
160
- });
161
-
162
- return { tables, views };
163
- };