peachsim 0.1.2252 → 0.1.2255
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/cli/commands/compat.ts +1 -1
- package/cli/commands/control.ts +1 -1
- package/cli/commands/package.ts +1 -1
- package/cli/commands/runtime.ts +1 -1
- package/cli/commands/upgrade.ts +2 -5
- package/cli/commands/version.ts +1 -1
- package/cli/native-input.ts +1 -1
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +2927 -2218
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +16 -1
- package/dist-lib/config.mjs +14 -1
- package/dist-lib/detox/index.cjs +2 -2
- package/dist-lib/dev-bundle-resolution.cjs +1 -1
- package/dist-lib/expo-swift-bundle.cjs +3110 -2402
- package/dist-lib/expo-swift-metadata.cjs +1 -1
- package/dist-lib/expo-swift-metadata.mjs +1 -1
- package/dist-lib/home-paths.cjs +1 -1
- package/dist-lib/host/bridge-host.cjs +2995 -2275
- package/dist-lib/host/fetch-proxy-handler.cjs +4 -4
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +2785 -2643
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +3 -2
- package/dist-lib/menu.cjs +1 -1
- package/dist-lib/menu.mjs +1 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +126 -42
- package/dist-lib/native-app-identity-project.cjs +2 -2
- package/dist-lib/native-app-identity-project.mjs +2 -3
- package/dist-lib/native-app-identity.cjs +1 -1
- package/dist-lib/native-app-identity.mjs +1 -1
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/pdfium-raster.cjs +1 -1
- package/dist-lib/pdfium-raster.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +24 -24
- package/dist-lib/public-origins-lib.json +126 -114
- package/dist-lib/react-native-host-modules.cjs +1 -1
- package/dist-lib/react-native-host-modules.mjs +1 -1
- package/dist-lib/reap-browser.cjs +1 -1
- package/dist-lib/scripts/dev-server-scanner.cjs +1 -1
- package/dist-lib/sdk.cjs +1 -1
- package/dist-lib/sdk.mjs +1 -1
- package/dist-lib/skills.cjs +3454 -2736
- package/dist-lib/swift-compile.cjs +97 -31
- package/dist-lib/swift-compile.mjs +100 -31
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +1 -1
- package/dist-lib/swift-submit.mjs +1 -1
- package/dist-lib/swift-toolchain.cjs +1 -1
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +2203 -1517
- package/dist-lib/vite.cjs +4804 -3498
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-engine/src/config.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/engine/scene-table.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/types.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +33 -1
- package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
- package/dist-types/packages/peach-globals/src/lockstepCaptureBridgeContract.d.ts +11 -0
- package/kotlin/sdk.tar.gz +0 -0
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/sdk/ios/wasm/include/__typedef_time_t.h +5 -0
- package/sdk/ios/wasm/include/ifaddrs.h +75 -0
- package/sdk/ios/wasm/include/machine/_types.h +1 -1
- package/sdk/ios/wasm/include/pthread.h +4 -0
- package/sdk/ios/wasm/include/unistd.h +2 -0
- package/{cli → src}/app-config.ts +5 -5
- package/src/bundle-channel.mjs +1 -1
- package/src/config.ts +29 -0
- package/src/core-data-entity-classes.ts +2 -2
- package/src/core-data-model.ts +681 -0
- package/src/expo-swift-host.ts +1 -1
- package/src/kotlin-host.ts +2 -1
- package/src/metro-plugin.ts +1 -3
- package/src/nitro-adapter.lock.json +236 -236
- package/src/nitro-bundle.ts +1 -1
- package/src/nitro-superset.lock.json +4 -4
- package/src/plist-bytes.ts +113 -0
- package/src/runtime-delivery.ts +3 -2
- package/src/swift-compile.ts +8 -1
- package/src/swift-distribution.lock.json +11 -11
- package/src/swift-guest-image-ledger.ts +2 -1
- package/src/swift-host.ts +18 -3
- package/src/turbo-bundle.ts +1 -1
- package/src/turbo-runtime.lock.json +20 -20
- package/src/vite-plugin-one.ts +68 -0
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { currentModelContents, parseModel, type Tag } from './core-data-entity-classes'
|
|
5
|
+
import {
|
|
6
|
+
buildBinaryPlist,
|
|
7
|
+
type BinaryPlistDictionary,
|
|
8
|
+
type BinaryPlistValue,
|
|
9
|
+
} from './plist-bytes'
|
|
10
|
+
|
|
11
|
+
// what xcode's momc writes for a model: each version is an NSKeyedArchiver
|
|
12
|
+
// plist of the model objects, and a versioned model's VersionInfo.plist names
|
|
13
|
+
// the current version and carries every version's entity hashes. keys, defaults
|
|
14
|
+
// and hash inputs were read from momc 27.1 output; a model feature whose output
|
|
15
|
+
// was not observed is refused, never guessed.
|
|
16
|
+
|
|
17
|
+
type UserInfo = [key: string, value: string][]
|
|
18
|
+
// the model being read and the major xcode version it targets
|
|
19
|
+
type Source = { model: string; tools: number }
|
|
20
|
+
type Common = {
|
|
21
|
+
name: string
|
|
22
|
+
optional: boolean
|
|
23
|
+
modifier: string | null
|
|
24
|
+
renaming: string
|
|
25
|
+
userInfo: UserInfo
|
|
26
|
+
}
|
|
27
|
+
type Attribute = Common & {
|
|
28
|
+
kind: 'attribute'
|
|
29
|
+
transient: boolean
|
|
30
|
+
type: number
|
|
31
|
+
className: string | null
|
|
32
|
+
defaultValue: string | number | boolean | null
|
|
33
|
+
transformer: string | null
|
|
34
|
+
flags: number
|
|
35
|
+
cloudEncryption: boolean
|
|
36
|
+
}
|
|
37
|
+
type Relationship = Common & {
|
|
38
|
+
kind: 'relationship'
|
|
39
|
+
destination: string
|
|
40
|
+
inverse: string | null
|
|
41
|
+
minCount: number
|
|
42
|
+
maxCount: number
|
|
43
|
+
deleteRule: number
|
|
44
|
+
ordered: boolean
|
|
45
|
+
}
|
|
46
|
+
type Property = Attribute | Relationship
|
|
47
|
+
type Index = {
|
|
48
|
+
name: string
|
|
49
|
+
elements: { property: string; ascending: boolean }[]
|
|
50
|
+
// a pre-xcode 9 model's indexed attribute becomes an index without an entity
|
|
51
|
+
owned: boolean
|
|
52
|
+
}
|
|
53
|
+
type Entity = {
|
|
54
|
+
name: string
|
|
55
|
+
className: string | null
|
|
56
|
+
abstract: boolean
|
|
57
|
+
parent: string | null
|
|
58
|
+
modifier: string | null
|
|
59
|
+
renaming: string
|
|
60
|
+
userInfo: UserInfo
|
|
61
|
+
properties: Property[]
|
|
62
|
+
indexes: Index[]
|
|
63
|
+
uniqueness: string[][]
|
|
64
|
+
}
|
|
65
|
+
type Model = {
|
|
66
|
+
entities: Entity[]
|
|
67
|
+
configurations: [name: string, entities: string[]][]
|
|
68
|
+
versionIdentifiers: string[]
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const attributeTypes: Record<string, [type: number, className: string | null]> = {
|
|
72
|
+
Undefined: [0, null],
|
|
73
|
+
'Integer 16': [100, 'NSNumber'],
|
|
74
|
+
'Integer 32': [200, 'NSNumber'],
|
|
75
|
+
'Integer 64': [300, 'NSNumber'],
|
|
76
|
+
Decimal: [400, 'NSDecimalNumber'],
|
|
77
|
+
Double: [500, 'NSNumber'],
|
|
78
|
+
Float: [600, 'NSNumber'],
|
|
79
|
+
String: [700, 'NSString'],
|
|
80
|
+
Boolean: [800, 'NSNumber'],
|
|
81
|
+
Date: [900, 'NSDate'],
|
|
82
|
+
Binary: [1000, 'NSData'],
|
|
83
|
+
UUID: [1100, 'NSUUID'],
|
|
84
|
+
URI: [1200, 'NSURL'],
|
|
85
|
+
Transformable: [1800, null],
|
|
86
|
+
}
|
|
87
|
+
const deleteRules: Record<string, number> = {
|
|
88
|
+
'No Action': 0,
|
|
89
|
+
Nullify: 1,
|
|
90
|
+
Cascade: 2,
|
|
91
|
+
Deny: 3,
|
|
92
|
+
}
|
|
93
|
+
// NSFlagsKey bits
|
|
94
|
+
const EXTERNAL_BINARY = 4
|
|
95
|
+
const PRESERVE_AFTER_DELETION = 16
|
|
96
|
+
|
|
97
|
+
function refuse(model: string, reason: string): never {
|
|
98
|
+
throw new Error(`Core Data model compilation is unproven for ${model}: ${reason}`)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function checkAttributes(model: string, tag: Tag, allowed: readonly string[]) {
|
|
102
|
+
for (const name of Object.keys(tag.attrs))
|
|
103
|
+
if (!allowed.includes(name)) refuse(model, `<${tag.name}> sets ${name}`)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function checkChildren(model: string, tag: Tag, allowed: readonly string[]) {
|
|
107
|
+
for (const child of tag.children)
|
|
108
|
+
if (!allowed.includes(child.name))
|
|
109
|
+
refuse(model, `<${tag.name} name="${tag.attrs.name}"> declares <${child.name}>`)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const yes = (value: string | undefined) => value === 'YES'
|
|
113
|
+
|
|
114
|
+
function userInfo(source: Source, owner: Tag): UserInfo {
|
|
115
|
+
const tag = owner.children.find((child) => child.name === 'userInfo')
|
|
116
|
+
if (tag) checkChildren(source.model, tag, ['entry'])
|
|
117
|
+
const entries = (tag?.children ?? []).map((entry): [string, string] => [
|
|
118
|
+
entry.attrs.key ?? '',
|
|
119
|
+
entry.attrs.value ?? '',
|
|
120
|
+
])
|
|
121
|
+
// tools before xcode 11 mark everything not declared syncable
|
|
122
|
+
return source.tools < 11 && owner.attrs.syncable !== 'YES'
|
|
123
|
+
? [...entries, ['com.apple.syncservices.Syncable', 'NO']]
|
|
124
|
+
: entries
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function defaultValue(model: string, member: Tag, type: string) {
|
|
128
|
+
const text = member.attrs.defaultValueString
|
|
129
|
+
if (text === undefined) return null
|
|
130
|
+
if (type.startsWith('Integer ') && /^-?\d+$/.test(text)) return Number(text)
|
|
131
|
+
if ((type === 'Double' || type === 'Float') && Number.isFinite(Number(text)))
|
|
132
|
+
return Number(text)
|
|
133
|
+
if (type === 'Boolean' && (text === 'YES' || text === 'NO')) return text === 'YES'
|
|
134
|
+
if (type === 'String') return text
|
|
135
|
+
refuse(model, `${member.attrs.name} has the ${type} default ${JSON.stringify(text)}`)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const common = (source: Source, member: Tag): Common => ({
|
|
139
|
+
name: member.attrs.name!,
|
|
140
|
+
optional: yes(member.attrs.optional),
|
|
141
|
+
modifier: member.attrs.versionHashModifier ?? null,
|
|
142
|
+
renaming: member.attrs.elementID ?? member.attrs.name!,
|
|
143
|
+
userInfo: userInfo(source, member),
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
function attribute(source: Source, member: Tag): Attribute {
|
|
147
|
+
checkAttributes(source.model, member, [
|
|
148
|
+
'name',
|
|
149
|
+
'optional',
|
|
150
|
+
'transient',
|
|
151
|
+
'attributeType',
|
|
152
|
+
'defaultValueString',
|
|
153
|
+
'usesScalarValueType',
|
|
154
|
+
'customClassName',
|
|
155
|
+
'valueTransformerName',
|
|
156
|
+
'indexed',
|
|
157
|
+
'versionHashModifier',
|
|
158
|
+
'elementID',
|
|
159
|
+
'allowsExternalBinaryDataStorage',
|
|
160
|
+
'preserveAfterDeletion',
|
|
161
|
+
'allowsCloudEncryption',
|
|
162
|
+
'syncable',
|
|
163
|
+
])
|
|
164
|
+
checkChildren(source.model, member, ['userInfo'])
|
|
165
|
+
const typeName = member.attrs.attributeType ?? ''
|
|
166
|
+
const known = attributeTypes[typeName]
|
|
167
|
+
if (!known)
|
|
168
|
+
refuse(source.model, `${member.attrs.name} has the attribute type ${typeName}`)
|
|
169
|
+
const [type, className] = known
|
|
170
|
+
if (member.attrs.customClassName !== undefined && typeName !== 'Transformable')
|
|
171
|
+
refuse(source.model, `${member.attrs.name} names a custom class for a ${typeName}`)
|
|
172
|
+
return {
|
|
173
|
+
kind: 'attribute',
|
|
174
|
+
...common(source, member),
|
|
175
|
+
transient: yes(member.attrs.transient),
|
|
176
|
+
type,
|
|
177
|
+
className:
|
|
178
|
+
typeName === 'Transformable' ? (member.attrs.customClassName ?? null) : className,
|
|
179
|
+
defaultValue: defaultValue(source.model, member, typeName),
|
|
180
|
+
transformer: member.attrs.valueTransformerName ?? null,
|
|
181
|
+
flags:
|
|
182
|
+
(yes(member.attrs.allowsExternalBinaryDataStorage) ? EXTERNAL_BINARY : 0) |
|
|
183
|
+
(yes(member.attrs.preserveAfterDeletion) ? PRESERVE_AFTER_DELETION : 0),
|
|
184
|
+
cloudEncryption: yes(member.attrs.allowsCloudEncryption),
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function relationship(source: Source, member: Tag): Relationship {
|
|
189
|
+
checkAttributes(source.model, member, [
|
|
190
|
+
'name',
|
|
191
|
+
'optional',
|
|
192
|
+
'toMany',
|
|
193
|
+
'ordered',
|
|
194
|
+
'minCount',
|
|
195
|
+
'maxCount',
|
|
196
|
+
'deletionRule',
|
|
197
|
+
'destinationEntity',
|
|
198
|
+
'inverseName',
|
|
199
|
+
'inverseEntity',
|
|
200
|
+
'versionHashModifier',
|
|
201
|
+
'elementID',
|
|
202
|
+
'syncable',
|
|
203
|
+
])
|
|
204
|
+
checkChildren(source.model, member, ['userInfo'])
|
|
205
|
+
const deleteRule = deleteRules[member.attrs.deletionRule ?? '']
|
|
206
|
+
if (deleteRule === undefined)
|
|
207
|
+
refuse(
|
|
208
|
+
source.model,
|
|
209
|
+
`${member.attrs.name} has the delete rule ${member.attrs.deletionRule}`,
|
|
210
|
+
)
|
|
211
|
+
const count = (value: string | undefined, fallback: number) =>
|
|
212
|
+
value === undefined ? fallback : Number(value)
|
|
213
|
+
return {
|
|
214
|
+
kind: 'relationship',
|
|
215
|
+
...common(source, member),
|
|
216
|
+
destination: member.attrs.destinationEntity!,
|
|
217
|
+
inverse: member.attrs.inverseName ?? null,
|
|
218
|
+
minCount: count(member.attrs.minCount, 0),
|
|
219
|
+
maxCount: count(member.attrs.maxCount, yes(member.attrs.toMany) ? 0 : 1),
|
|
220
|
+
deleteRule,
|
|
221
|
+
ordered: yes(member.attrs.ordered),
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function entity(source: Source, tag: Tag): Entity {
|
|
226
|
+
checkAttributes(source.model, tag, [
|
|
227
|
+
'name',
|
|
228
|
+
'representedClassName',
|
|
229
|
+
'parentEntity',
|
|
230
|
+
'isAbstract',
|
|
231
|
+
'versionHashModifier',
|
|
232
|
+
'elementID',
|
|
233
|
+
'syncable',
|
|
234
|
+
'codeGenerationType',
|
|
235
|
+
])
|
|
236
|
+
checkChildren(source.model, tag, [
|
|
237
|
+
'attribute',
|
|
238
|
+
'relationship',
|
|
239
|
+
'fetchIndex',
|
|
240
|
+
'uniquenessConstraints',
|
|
241
|
+
'userInfo',
|
|
242
|
+
])
|
|
243
|
+
const properties = tag.children.flatMap((member): Property[] =>
|
|
244
|
+
member.name === 'attribute'
|
|
245
|
+
? [attribute(source, member)]
|
|
246
|
+
: member.name === 'relationship'
|
|
247
|
+
? [relationship(source, member)]
|
|
248
|
+
: [],
|
|
249
|
+
)
|
|
250
|
+
const indexes = tag.children
|
|
251
|
+
.filter((child) => child.name === 'fetchIndex')
|
|
252
|
+
.map((index): Index => {
|
|
253
|
+
checkChildren(source.model, index, ['fetchIndexElement'])
|
|
254
|
+
return {
|
|
255
|
+
name: index.attrs.name!,
|
|
256
|
+
owned: true,
|
|
257
|
+
elements: index.children.map((element) => {
|
|
258
|
+
checkAttributes(source.model, element, ['property', 'type', 'order'])
|
|
259
|
+
if (element.attrs.type !== 'Binary' || element.attrs.property === undefined)
|
|
260
|
+
refuse(
|
|
261
|
+
source.model,
|
|
262
|
+
`${tag.attrs.name}.${index.attrs.name} has a non-binary element`,
|
|
263
|
+
)
|
|
264
|
+
return {
|
|
265
|
+
property: element.attrs.property,
|
|
266
|
+
ascending: element.attrs.order !== 'descending',
|
|
267
|
+
}
|
|
268
|
+
}),
|
|
269
|
+
}
|
|
270
|
+
})
|
|
271
|
+
// momc turns each indexed attribute into a one-element index after the declared ones,
|
|
272
|
+
// named for the attribute alone when the source.model targets tools before xcode 9
|
|
273
|
+
const indexed = tag.children
|
|
274
|
+
.filter((member) => member.name === 'attribute' && yes(member.attrs.indexed))
|
|
275
|
+
.map((member) => member.attrs.name!)
|
|
276
|
+
.sort()
|
|
277
|
+
for (const property of indexed)
|
|
278
|
+
indexes.push({
|
|
279
|
+
name:
|
|
280
|
+
source.tools < 9
|
|
281
|
+
? property
|
|
282
|
+
: `by${property.charAt(0).toUpperCase()}${property.slice(1)}Index`,
|
|
283
|
+
elements: [{ property, ascending: true }],
|
|
284
|
+
owned: source.tools >= 9,
|
|
285
|
+
})
|
|
286
|
+
const uniqueness = tag.children
|
|
287
|
+
.filter((child) => child.name === 'uniquenessConstraints')
|
|
288
|
+
.flatMap((group) => {
|
|
289
|
+
checkChildren(source.model, group, ['uniquenessConstraint'])
|
|
290
|
+
return group.children.map((constraint) => {
|
|
291
|
+
checkChildren(source.model, constraint, ['constraint'])
|
|
292
|
+
return constraint.children.map((item) => item.attrs.value!)
|
|
293
|
+
})
|
|
294
|
+
})
|
|
295
|
+
return {
|
|
296
|
+
name: tag.attrs.name!,
|
|
297
|
+
className: tag.attrs.representedClassName ?? null,
|
|
298
|
+
abstract: yes(tag.attrs.isAbstract),
|
|
299
|
+
parent: tag.attrs.parentEntity ?? null,
|
|
300
|
+
modifier: tag.attrs.versionHashModifier ?? null,
|
|
301
|
+
renaming: tag.attrs.elementID ?? tag.attrs.name!,
|
|
302
|
+
userInfo: userInfo(source, tag),
|
|
303
|
+
properties,
|
|
304
|
+
indexes,
|
|
305
|
+
uniqueness,
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function readModel(model: string, contents: string): Model {
|
|
310
|
+
const root = parseModel(readFileSync(contents, 'utf8'))
|
|
311
|
+
const tag = root.children.find((child) => child.name === 'model')
|
|
312
|
+
if (!tag) refuse(model, 'the contents file has no model element')
|
|
313
|
+
checkChildren(model, tag, ['entity', 'configuration', 'elements'])
|
|
314
|
+
const tools = /^Xcode (\d+)/.exec(tag.attrs.minimumToolsVersion ?? '')
|
|
315
|
+
const source: Source = { model, tools: tools ? Number(tools[1]) : Infinity }
|
|
316
|
+
const entities = tag.children
|
|
317
|
+
.filter((child) => child.name === 'entity')
|
|
318
|
+
.map((child) => entity(source, child))
|
|
319
|
+
const names = new Set(entities.map((item) => item.name))
|
|
320
|
+
for (const item of entities) {
|
|
321
|
+
if (item.parent !== null && !names.has(item.parent))
|
|
322
|
+
refuse(model, `${item.name} names the missing parent entity ${item.parent}`)
|
|
323
|
+
for (const property of item.properties)
|
|
324
|
+
if (property.kind === 'relationship' && !names.has(property.destination))
|
|
325
|
+
refuse(model, `${item.name}.${property.name} names a missing destination`)
|
|
326
|
+
}
|
|
327
|
+
const configurations = tag.children
|
|
328
|
+
.filter((child) => child.name === 'configuration')
|
|
329
|
+
.map((child): [string, string[]] => {
|
|
330
|
+
checkChildren(model, child, ['memberEntity'])
|
|
331
|
+
return [child.attrs.name!, child.children.map((member) => member.attrs.name!)]
|
|
332
|
+
})
|
|
333
|
+
return {
|
|
334
|
+
entities,
|
|
335
|
+
configurations,
|
|
336
|
+
versionIdentifiers: [tag.attrs.userDefinedModelVersionIdentifier ?? ''],
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
type Uid = { CF$UID: number }
|
|
341
|
+
const uid = (index: number): Uid => ({ CF$UID: index })
|
|
342
|
+
const NULL = uid(0)
|
|
343
|
+
|
|
344
|
+
const classChains: Record<string, string[]> = {
|
|
345
|
+
NSManagedObjectModel: ['NSManagedObjectModel', 'NSObject'],
|
|
346
|
+
NSEntityDescription: ['NSEntityDescription', 'NSObject'],
|
|
347
|
+
NSAttributeDescription: ['NSAttributeDescription', 'NSPropertyDescription', 'NSObject'],
|
|
348
|
+
NSRelationshipDescription: [
|
|
349
|
+
'NSRelationshipDescription',
|
|
350
|
+
'NSPropertyDescription',
|
|
351
|
+
'NSObject',
|
|
352
|
+
],
|
|
353
|
+
NSFetchIndexDescription: ['NSFetchIndexDescription', 'NSObject'],
|
|
354
|
+
NSFetchIndexElementDescription: ['NSFetchIndexElementDescription', 'NSObject'],
|
|
355
|
+
NSDictionary: ['NSDictionary', 'NSObject'],
|
|
356
|
+
NSMutableDictionary: ['NSMutableDictionary', 'NSDictionary', 'NSObject'],
|
|
357
|
+
NSArray: ['NSArray', 'NSObject'],
|
|
358
|
+
NSMutableArray: ['NSMutableArray', 'NSArray', 'NSObject'],
|
|
359
|
+
NSSet: ['NSSet', 'NSObject'],
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// the NSKeyedArchiver object table: objects reserve their slot first so the
|
|
363
|
+
// model, its entities and their properties can reference one another.
|
|
364
|
+
class KeyedArchive {
|
|
365
|
+
objects: BinaryPlistValue[] = ['$null']
|
|
366
|
+
classes = new Map<string, Uid>()
|
|
367
|
+
reserve() {
|
|
368
|
+
this.objects.push('')
|
|
369
|
+
return this.objects.length - 1
|
|
370
|
+
}
|
|
371
|
+
fill(index: number, className: string, fields: BinaryPlistDictionary) {
|
|
372
|
+
let classUid = this.classes.get(className)
|
|
373
|
+
if (!classUid) {
|
|
374
|
+
classUid = this.add({ $classname: className, $classes: classChains[className]! })
|
|
375
|
+
this.classes.set(className, classUid)
|
|
376
|
+
}
|
|
377
|
+
this.objects[index] = { ...fields, $class: classUid }
|
|
378
|
+
return uid(index)
|
|
379
|
+
}
|
|
380
|
+
add(value: BinaryPlistValue) {
|
|
381
|
+
this.objects.push(value)
|
|
382
|
+
return uid(this.objects.length - 1)
|
|
383
|
+
}
|
|
384
|
+
string(value: string | null) {
|
|
385
|
+
return value === null ? NULL : this.add(value)
|
|
386
|
+
}
|
|
387
|
+
array(values: Uid[], className = 'NSMutableArray') {
|
|
388
|
+
return this.fill(this.reserve(), className, { 'NS.objects': values })
|
|
389
|
+
}
|
|
390
|
+
dictionary(entries: [key: string, value: Uid][], className = 'NSMutableDictionary') {
|
|
391
|
+
return this.fill(this.reserve(), className, {
|
|
392
|
+
'NS.keys': entries.map(([key]) => this.add(key)),
|
|
393
|
+
'NS.objects': entries.map(([, value]) => value),
|
|
394
|
+
})
|
|
395
|
+
}
|
|
396
|
+
userInfo(entries: UserInfo) {
|
|
397
|
+
return this.dictionary(
|
|
398
|
+
entries.map(([key, value]) => [key, this.add(value)]),
|
|
399
|
+
'NSDictionary',
|
|
400
|
+
)
|
|
401
|
+
}
|
|
402
|
+
build() {
|
|
403
|
+
return buildBinaryPlist({
|
|
404
|
+
$archiver: 'NSKeyedArchiver',
|
|
405
|
+
$objects: this.objects,
|
|
406
|
+
$top: { root: uid(1) },
|
|
407
|
+
$version: 100000,
|
|
408
|
+
})
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function archiveModel(model: Model) {
|
|
413
|
+
const archive = new KeyedArchive()
|
|
414
|
+
const modelIndex = archive.reserve()
|
|
415
|
+
const entityIndex = new Map(
|
|
416
|
+
model.entities.map((item) => [item.name, archive.reserve()]),
|
|
417
|
+
)
|
|
418
|
+
const propertyIndex = new Map<string, number>()
|
|
419
|
+
for (const item of model.entities)
|
|
420
|
+
for (const property of item.properties)
|
|
421
|
+
propertyIndex.set(`${item.name}.${property.name}`, archive.reserve())
|
|
422
|
+
const entityUid = (name: string) => uid(entityIndex.get(name)!)
|
|
423
|
+
for (const item of model.entities) {
|
|
424
|
+
const self = entityUid(item.name)
|
|
425
|
+
const properties = item.properties.map((property): [string, Uid] => {
|
|
426
|
+
const index = propertyIndex.get(`${item.name}.${property.name}`)!
|
|
427
|
+
const shared: BinaryPlistDictionary = {
|
|
428
|
+
NSEntity: self,
|
|
429
|
+
NSPropertyName: archive.add(property.name),
|
|
430
|
+
NSRenamingIdentifier: archive.add(property.renaming),
|
|
431
|
+
...(property.optional ? { NSIsOptional: true } : {}),
|
|
432
|
+
...(property.modifier !== null
|
|
433
|
+
? { NSVersionHashModifier: archive.add(property.modifier) }
|
|
434
|
+
: {}),
|
|
435
|
+
...(property.userInfo.length > 0
|
|
436
|
+
? { NSUserInfo: archive.userInfo(property.userInfo) }
|
|
437
|
+
: {}),
|
|
438
|
+
}
|
|
439
|
+
if (property.kind === 'attribute')
|
|
440
|
+
return [
|
|
441
|
+
property.name,
|
|
442
|
+
archive.fill(index, 'NSAttributeDescription', {
|
|
443
|
+
...shared,
|
|
444
|
+
NSAttributeType: property.type,
|
|
445
|
+
NSAttributeValueClassName: archive.string(property.className),
|
|
446
|
+
NSDefaultValue:
|
|
447
|
+
property.defaultValue === null ? NULL : archive.add(property.defaultValue),
|
|
448
|
+
NSFlagsKey: property.flags,
|
|
449
|
+
NSValueTransformerName: archive.string(property.transformer),
|
|
450
|
+
...(property.transient ? { NSIsTransient: true } : {}),
|
|
451
|
+
...(property.cloudEncryption ? { NSAllowsCloudEncryption: true } : {}),
|
|
452
|
+
}),
|
|
453
|
+
]
|
|
454
|
+
const destination = model.entities.find(
|
|
455
|
+
(other) => other.name === property.destination,
|
|
456
|
+
)!
|
|
457
|
+
const inverse =
|
|
458
|
+
property.inverse === null
|
|
459
|
+
? undefined
|
|
460
|
+
: propertyIndex.get(`${destination.name}.${property.inverse}`)
|
|
461
|
+
return [
|
|
462
|
+
property.name,
|
|
463
|
+
archive.fill(index, 'NSRelationshipDescription', {
|
|
464
|
+
...shared,
|
|
465
|
+
NSDeleteRule: property.deleteRule,
|
|
466
|
+
NSDestinationEntity: entityUid(property.destination),
|
|
467
|
+
NSInverseRelationship: inverse === undefined ? NULL : uid(inverse),
|
|
468
|
+
NSMaxCount: property.maxCount,
|
|
469
|
+
NSMinCount: property.minCount,
|
|
470
|
+
_NSDestinationEntityName: archive.add(property.destination),
|
|
471
|
+
_NSInverseRelationshipName: archive.string(property.inverse),
|
|
472
|
+
...(property.ordered ? { NSIsOrdered: true } : {}),
|
|
473
|
+
}),
|
|
474
|
+
]
|
|
475
|
+
})
|
|
476
|
+
const indexes =
|
|
477
|
+
item.indexes.length === 0
|
|
478
|
+
? {}
|
|
479
|
+
: {
|
|
480
|
+
NSCompoundIndexes: archive.array(
|
|
481
|
+
item.indexes
|
|
482
|
+
.filter((index) => index.elements.length >= 2)
|
|
483
|
+
.map((index) =>
|
|
484
|
+
archive.array(
|
|
485
|
+
index.elements.map((element) => archive.add(element.property)),
|
|
486
|
+
),
|
|
487
|
+
),
|
|
488
|
+
),
|
|
489
|
+
NSFetchIndexDescriptions: archive.array(
|
|
490
|
+
item.indexes.map((index) => {
|
|
491
|
+
const at = archive.reserve()
|
|
492
|
+
return archive.fill(at, 'NSFetchIndexDescription', {
|
|
493
|
+
NSEntity: index.owned ? self : NULL,
|
|
494
|
+
NSIndexName: archive.add(index.name),
|
|
495
|
+
NSPartialIndexPredicate: NULL,
|
|
496
|
+
NSIndexElements: archive.array(
|
|
497
|
+
index.elements.map((element) =>
|
|
498
|
+
archive.fill(archive.reserve(), 'NSFetchIndexElementDescription', {
|
|
499
|
+
NSAscending: element.ascending,
|
|
500
|
+
NSFetchIndexDescription: uid(at),
|
|
501
|
+
NSFetchIndexElementType: 0,
|
|
502
|
+
NSPropertyName: archive.add(element.property),
|
|
503
|
+
}),
|
|
504
|
+
),
|
|
505
|
+
'NSArray',
|
|
506
|
+
),
|
|
507
|
+
})
|
|
508
|
+
}),
|
|
509
|
+
),
|
|
510
|
+
}
|
|
511
|
+
archive.fill(entityIndex.get(item.name)!, 'NSEntityDescription', {
|
|
512
|
+
NSClassNameForEntity: archive.string(item.className),
|
|
513
|
+
NSEntityName: archive.add(item.name),
|
|
514
|
+
...(item.abstract ? { NSIsAbstract: true } : {}),
|
|
515
|
+
NSManagedObjectModel: uid(modelIndex),
|
|
516
|
+
NSProperties: archive.dictionary(properties),
|
|
517
|
+
NSRenamingIdentifier: archive.add(item.renaming),
|
|
518
|
+
NSSubentities: archive.dictionary(
|
|
519
|
+
model.entities
|
|
520
|
+
.filter((other) => other.parent === item.name)
|
|
521
|
+
.map((other) => [other.name, entityUid(other.name)]),
|
|
522
|
+
),
|
|
523
|
+
NSSuperentity: item.parent === null ? NULL : entityUid(item.parent),
|
|
524
|
+
NSUserInfo: archive.userInfo(item.userInfo),
|
|
525
|
+
NSVersionHashModifier: archive.string(item.modifier),
|
|
526
|
+
...indexes,
|
|
527
|
+
...(item.uniqueness.length > 0
|
|
528
|
+
? {
|
|
529
|
+
NSUniqueTuples: archive.array(
|
|
530
|
+
item.uniqueness.map((tuple) =>
|
|
531
|
+
archive.array(tuple.map((name) => archive.add(name))),
|
|
532
|
+
),
|
|
533
|
+
),
|
|
534
|
+
}
|
|
535
|
+
: {}),
|
|
536
|
+
})
|
|
537
|
+
}
|
|
538
|
+
archive.fill(modelIndex, 'NSManagedObjectModel', {
|
|
539
|
+
NSEntities: archive.dictionary(
|
|
540
|
+
model.entities.map((item) => [item.name, entityUid(item.name)]),
|
|
541
|
+
),
|
|
542
|
+
NSFetchRequestTemplates: NULL,
|
|
543
|
+
NSVersionIdentifiers: archive.array(
|
|
544
|
+
model.versionIdentifiers.map((identifier) => archive.add(identifier)),
|
|
545
|
+
'NSSet',
|
|
546
|
+
),
|
|
547
|
+
...(model.configurations.length > 0
|
|
548
|
+
? {
|
|
549
|
+
NSConfigurations: archive.dictionary(
|
|
550
|
+
model.configurations.map(([name, members]) => [
|
|
551
|
+
name,
|
|
552
|
+
archive.array(members.map(entityUid), 'NSSet'),
|
|
553
|
+
]),
|
|
554
|
+
),
|
|
555
|
+
}
|
|
556
|
+
: {}),
|
|
557
|
+
})
|
|
558
|
+
return archive.build()
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const sha256 = (...parts: (Buffer | string | number[])[]) =>
|
|
562
|
+
createHash('sha256')
|
|
563
|
+
.update(
|
|
564
|
+
Buffer.concat(
|
|
565
|
+
parts.map((part) =>
|
|
566
|
+
Array.isArray(part) ? Buffer.from(part) : Buffer.from(part),
|
|
567
|
+
),
|
|
568
|
+
),
|
|
569
|
+
)
|
|
570
|
+
.digest()
|
|
571
|
+
|
|
572
|
+
function u32(value: number) {
|
|
573
|
+
const bytes = Buffer.alloc(4)
|
|
574
|
+
bytes.writeUInt32LE(value >>> 0)
|
|
575
|
+
return bytes
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function propertyHash(property: Property) {
|
|
579
|
+
const transient = property.kind === 'attribute' && property.transient
|
|
580
|
+
const base = sha256(
|
|
581
|
+
property.name,
|
|
582
|
+
[(property.optional ? 1 : 0) | (transient ? 2 : 0), 0],
|
|
583
|
+
property.modifier ?? '',
|
|
584
|
+
)
|
|
585
|
+
if (property.kind === 'attribute')
|
|
586
|
+
return sha256(
|
|
587
|
+
base,
|
|
588
|
+
u32(property.type),
|
|
589
|
+
property.type === 1000 && property.flags & EXTERNAL_BINARY ? [1] : [],
|
|
590
|
+
property.flags & PRESERVE_AFTER_DELETION ? [1] : [],
|
|
591
|
+
)
|
|
592
|
+
return sha256(
|
|
593
|
+
base,
|
|
594
|
+
property.destination,
|
|
595
|
+
property.inverse ?? '',
|
|
596
|
+
u32(property.maxCount),
|
|
597
|
+
u32(property.minCount),
|
|
598
|
+
property.ordered ? [1, 0] : [],
|
|
599
|
+
)
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** each entity's version hash, by entity name in UTF-16 order, as Core Data computes it. */
|
|
603
|
+
function entityHashes(model: Model) {
|
|
604
|
+
const byName = new Map(model.entities.map((item) => [item.name, item]))
|
|
605
|
+
const allProperties = (item: Entity): Property[] => [
|
|
606
|
+
...(item.parent === null ? [] : allProperties(byName.get(item.parent)!)),
|
|
607
|
+
...item.properties,
|
|
608
|
+
]
|
|
609
|
+
const hash = (item: Entity): Buffer =>
|
|
610
|
+
sha256(
|
|
611
|
+
item.name,
|
|
612
|
+
[item.abstract ? 1 : 0],
|
|
613
|
+
item.parent === null ? [] : hash(byName.get(item.parent)!),
|
|
614
|
+
...allProperties(item)
|
|
615
|
+
.filter((property) => property.kind !== 'attribute' || !property.transient)
|
|
616
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))
|
|
617
|
+
.map(propertyHash),
|
|
618
|
+
item.modifier ?? '',
|
|
619
|
+
item.uniqueness
|
|
620
|
+
.map((tuple) => tuple.join('.'))
|
|
621
|
+
.sort()
|
|
622
|
+
.join(''),
|
|
623
|
+
)
|
|
624
|
+
return model.entities
|
|
625
|
+
.map((item): [string, Buffer] => [item.name, hash(item)])
|
|
626
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* the compiled files momc writes for an .xcdatamodeld (`<Name>.momd/<Version>.mom`
|
|
631
|
+
* per version plus VersionInfo.plist) or a bare .xcdatamodel (`<Name>.mom`),
|
|
632
|
+
* keyed by their path in the bundle.
|
|
633
|
+
*/
|
|
634
|
+
export function compileCoreDataModel(directory: string): Record<string, Buffer> {
|
|
635
|
+
const extension = path.extname(directory)
|
|
636
|
+
const name = path.basename(directory, extension)
|
|
637
|
+
if (extension === '.xcdatamodel')
|
|
638
|
+
return {
|
|
639
|
+
[`${name}.mom`]: archiveModel(readModel(name, path.join(directory, 'contents'))),
|
|
640
|
+
}
|
|
641
|
+
const current = currentModelContents(directory)
|
|
642
|
+
if (!current) refuse(name, 'the current model version is not named')
|
|
643
|
+
const files: Record<string, Buffer> = {}
|
|
644
|
+
const checksums: BinaryPlistDictionary = {}
|
|
645
|
+
const hashes: BinaryPlistDictionary = {}
|
|
646
|
+
for (const entry of readdirSync(directory)
|
|
647
|
+
.filter((item) => item.endsWith('.xcdatamodel'))
|
|
648
|
+
.sort()) {
|
|
649
|
+
const version = entry.slice(0, -'.xcdatamodel'.length)
|
|
650
|
+
const model = readModel(`${name}/${version}`, path.join(directory, entry, 'contents'))
|
|
651
|
+
files[`${name}.momd/${version}.mom`] = archiveModel(model)
|
|
652
|
+
const entities = entityHashes(model)
|
|
653
|
+
hashes[version] = Object.fromEntries(entities)
|
|
654
|
+
checksums[version] = sha256(...entities.map(([, hash]) => hash)).toString('base64')
|
|
655
|
+
}
|
|
656
|
+
// the current version is named only when the model directory names one
|
|
657
|
+
const named = existsSync(path.join(directory, '.xccurrentversion'))
|
|
658
|
+
? {
|
|
659
|
+
NSManagedObjectModel_CurrentVersionName: path.basename(
|
|
660
|
+
path.dirname(current),
|
|
661
|
+
'.xcdatamodel',
|
|
662
|
+
),
|
|
663
|
+
}
|
|
664
|
+
: {}
|
|
665
|
+
files[`${name}.momd/VersionInfo.plist`] = buildBinaryPlist({
|
|
666
|
+
...named,
|
|
667
|
+
NSManagedObjectModel_VersionChecksums: checksums,
|
|
668
|
+
NSManagedObjectModel_VersionHashes: hashes,
|
|
669
|
+
})
|
|
670
|
+
return files
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/** the data model directories that hold any of the files, outermost first. */
|
|
674
|
+
export function coreDataModelDirectories(files: Iterable<string>) {
|
|
675
|
+
const models = new Set<string>()
|
|
676
|
+
for (const file of files) {
|
|
677
|
+
const match = /^(.*?\.xcdatamodeld?)(?:[\\/]|$)/.exec(file)
|
|
678
|
+
if (match) models.add(match[1]!)
|
|
679
|
+
}
|
|
680
|
+
return [...models].sort()
|
|
681
|
+
}
|
package/src/expo-swift-host.ts
CHANGED
|
@@ -10,9 +10,9 @@ import path from 'node:path'
|
|
|
10
10
|
import { fileURLToPath } from 'node:url'
|
|
11
11
|
import { promisify } from 'node:util'
|
|
12
12
|
import { EXPO_EAGER_NATIVE_VIEWS } from '../../peach-compat/src/stubs/native-seams/expo-eager-seam-contract'
|
|
13
|
-
import { loadRNXAppConfig } from '../cli/app-config'
|
|
14
13
|
import { resolveAppProject } from '../cli/app-project'
|
|
15
14
|
import { peachAnsweredNativePackages } from './answeredNativePackages'
|
|
15
|
+
import { loadRNXAppConfig } from './app-config'
|
|
16
16
|
import { isLoopbackHost } from './backend-origin'
|
|
17
17
|
import { autolinkerAppleFlags } from './expo-autolinking'
|
|
18
18
|
import {
|